Ambiguous type variable

Simon Peyton-Jones simonpj@microsoft.com
Thu, 23 Jan 2003 14:07:57 -0000


I've been working on improving this error message.  Here's the current
version:

R.hs:1:
    Ambiguous type variable `a' in constraints
      `Random a' arising from use of `randomRs' at R.hs:4
      `Num a' arising from the literal `0' at R.hs:4
    Possible cause: the monomorphism restriction applied to the
following:
      f :: Int -> [a] (bound at R.hs:4)

better, eh?

| -----Original Message-----
| From: Jorge Adriano [mailto:jadrian@mat.uc.pt]
| Sent: 22 January 2003 18:28
| To: GHC Users Mailing List
| Subject: Ambiguous type variable
|=20
| Hi all,
|=20
| This works fine, as expected
| > f :: (Num a, Random a) =3D> Int -> [a]
| > f =3D randomRs (0,1).mkStdGen
|=20
| If I skip the type signature, though, I get the following error
messages:
| Main.hs:14:
|     Ambiguous type variable(s) `a' in the constraint `Random a'
|     arising from use of `randomRs' at Main.hs:14
|     In the first argument of `(.)', namely `randomRs (0, 1)'
|     In the definition of `f': (randomRs (0, 1)) . mkStdGen
|=20
| Main.hs:14:
|     Ambiguous type variable(s) `a' in the constraint `Num a'
|     arising from the literal `1' at Main.hs:14
|     In the first argument of `randomRs', namely `(0, 1)'
|     In the first argument of `(.)', namely `randomRs (0, 1)'
|=20
| Why exctly can't ghci figure how the type of f?
|=20
| This just happens when loading the code from a file,
| > :t randomRs (0,1).mkStdGen
| in ghci works fine.
|=20
| J.A.
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users@haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users