I'm reading chapter 9 (More Input and More Output) of Learn You a Haskell for Great Good. Now I'm about to learn how to generate random numbers in Haskell (it's so exciting!). Here is a citation from the book:
To manually make a random generator, use the
mkStdGenfunction. It has a type ofmkStdGen :: Int -> StdGen. It takes an integer, and based on that, gives us a random generator. Okay then, let’s try usingrandomandmkStdGenintandem to get a (hardly) random number.
ghci> random (mkStdGen 100)
<interactive>:1:0:
Ambiguous type variable `a' in the constraint:
`Random a' arising from a use of `random' at <interactive>:1:0-20
Probable fix: add a type signature that fixes these type variable(s)
What’s this? Ah, right, the
randomfunction can return a value of any type that’s part of theRandomtype class, so we need to inform Haskell which type we want. Also let’s not forget that it returns a random value and a random generator in a pair.
The problem is that I don't get this error, in fact, I can do the following:
*Main> :m + System.Random
*Main System.Random> random (mkStdGen 100)
(-3633736515773289454,693699796 2103410263)
So my question is why can I evaluate this expression without getting the exception?