Ambiguous type variable

Jorge Adriano jadrian@mat.uc.pt
Wed, 22 Jan 2003 18:28:03 +0000


Hi all,=20

This works fine, as expected
> f :: (Num a, Random a) =3D> Int -> [a]
> f =3D 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,=20
> :t randomRs (0,1).mkStdGen
in ghci works fine.

J.A.