[Haskell-cafe] Convert IO Int to Int
Miguel Mitrofanov
miguelimo38 at yandex.ru
Wed Jun 10 07:58:29 EDT 2009
"r <- randomRIO (1,10)" is NOT the source of error. Why do you think it is?
ptrash wrote on 10.06.2009 15:55:
> Hi,
>
> I have tried on the console to write
>
> x <- randomRIO(1,10)
> :t x
>
> Everythings fine and the type of x is
> x :: Integer
>
> 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?
More information about the Haskell-Cafe
mailing list