[Haskell-beginners] ghci and randomRs

Jeff C. Britton jcb at iteris.com
Tue Sep 16 23:55:16 UTC 2014


Thanks Francesco.
This actually helped me.

--Jeff

-----Original Message-----
From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of Francesco Ariis
Sent: Tuesday, September 16, 2014 12:06 PM
To: beginners at haskell.org
Subject: Re: [Haskell-beginners] ghci and randomRs

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) _______________________________________________
Beginners mailing list
Beginners at haskell.org
http://www.haskell.org/mailman/listinfo/beginners


More information about the Beginners mailing list