
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 | | Hi all, | | This works fine, as expected | > f :: (Num a, Random a) => Int -> [a] | > f = randomRs (0,1).mkStdGen | | 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 | | 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)' | | Why exctly can't ghci figure how the type of f? | | This just happens when loading the code from a file, | > :t randomRs (0,1).mkStdGen | in ghci works fine. | | J.A. | _______________________________________________ | Glasgow-haskell-users mailing list | Glasgow-haskell-users@haskell.org | http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

"Simon Peyton-Jones"
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)
How about explicitly suggesting a type signature? Referring to "the monomorphism restriction" will probably not be helpful to novices, who are the ones who need clear error messages the most. -kzm -- If I haven't seen further, it is by standing in the footprints of giants
participants (2)
-
ketil@ii.uib.no
-
Simon Peyton-Jones