Error with main function

haskell

Solution

When you compile this, you get

Ambiguous type variable `a0' in the constraints ....

This is because in ghci, the type of `1` and `10` defaults to Integer, but the compiler doesn't have the same defaulting rules.

Since you're printing them before doing anything else, it can't deduce the type.

All you need to do is add an explicit type signature, for example

main = newStdGen >>= print . take 5 . randomRs (1::Int,10)

Problem

I'm new to Haskell and still trying to workout some of syntax/idioms. Can anyone explain what I'm doing wrong in this code? `main` should print out a list of 5 random numbers. This works find in GHCi, but not in a file. What am I missing? ``` import System.Random main = newStdGen >>= print . take 5 . randomRs (1,10) ```

Original source