[Haskell-cafe] Convert IO Int to Int
Iain Barnett
iainspeed at gmail.com
Wed Jun 10 08:08:32 EDT 2009
On 10 Jun 2009, at 12:55 pm, ptrash wrote:
>
>
> Now I have tried to write a Method which gives me a Number of
> random numbers
> the same way but it doesn't work.
>
> randomList :: Int -> [Integer]
> randomList 0 = []
> randomList n = do
> r <- randomRIO (1, 10)
> r:randomList(n-1)
>
> It says Couldn't match expected type `IO t' against inferred type
> `[t]'
> r <- randomRIO (1,10) causes an error. But why does it work on the
> console?
> Is there a way to solve it another way?
>
I had the same problem a while back, the thread is here
http://www.mail-archive.com/haskell-cafe@haskell.org/msg46194.html
the console uses IO already, so it's not a problem there. I ended up
learning about the >>= operator, and that helped a lot. Anyway, lots
of helpful links in that mail thread.
Iain
More information about the Haskell-Cafe
mailing list