[Haskell-beginners] ghci and randomRs

Francesco Ariis fa-ml at ariis.it
Tue Sep 16 19:05:49 UTC 2014


On Tue, Sep 16, 2014 at 05:43:04PM +0000, Jeff C. Britton wrote:
> Ok, I got it now.  I was misunderstanding how the REPL was interacting with the IO Monad.
> I had once tried
> do { g <- newStdGen; take 10 $ randomRs (1,6) g  }
>
> but I actually needed this
> do { g <- newStdGen; return . take 10 $ randomRs (1,6) g  }
>
> Thanks,
> Jeff

I am sure you have already figured it out, but in case you didn't,
this works too:

λ> :m +System.Random
λ> g <- newStdGen
λ> take 10 $ randomRs (1,6) g
[3,3,5,1,6,6,3,3,1,6]
λ>

(and keeps IO actions apart from pure code)


More information about the Beginners mailing list