[Haskell-cafe] Convert IO Int to Int

Magnus Therning magnus at therning.org
Tue Jun 9 09:57:24 EDT 2009


On Tue, Jun 9, 2009 at 2:52 PM, ptrash<ptrash at web.de> wrote:
>
> Hmm...it am not getting through it. I just want to generate a random number
> and then compare it with other numbers. Something like
>
> r = randomRIO (1, 10)
> if (r > 5) then... else ...

You have to do it inside the IO monad, something like

    myFunc  = do
        r <- randomRIO (1, 10
        if r > 5
            then ...
            else ...

/M

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe


More information about the Haskell-Cafe mailing list