Ambiguous type variable

Olaf Chitil
Wed, 22 Jan 2003 18:42:37 +0000

Jorge Adriano wrote:
> 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:
> ...

You just tripped over the infamous monomorphic restriction of Haskell:
A variable that is defined like a constant (no arguments before "=") is
not allowed to be overloaded (have a class context), except when the
type of the variable is explicitly given.
Maybe it would be possible to generate a more informative type error
message in such cases? 


 Dept. of Computer Science, The University of York, York YO10 5DD, UK. 
 Tel: +44 1904 434756; Fax: +44 1904 432767