[Haskell-cafe] Re: Haskell-Cafe Digest, Vol 47, Issue 237

Chad Scherrer chad.scherrer at gmail.com
Tue Jul 31 14:10:32 EDT 2007

Maybe I'm going about this the wrong way, but using the State monad
for random numbers was always leaky for me. Any time I use it, I have
to go through and strategically place "seq"s to counter the excessive
laziness. IO and ST have worked well, and seem to be faster as well
(though that's purely self-anecdotal evidence). I'm stuck in IO anyway
for a lot of this (reading data from files to build my lookup tables),
so ST didn't seem worth the extra trouble either. Admittedly it would
have been good practice, though.

What monad do most people use for random numbers? If performance is an
issue, do you still use State? Generating an infinite list of randoms
seems like a good approach if you just use them in one place, but
beyond that you end up passing around the tail of the list at each
step, so then you may as well wrap the generator in State, I think.


> Chad Scherrer wrote:
> > I prefer the purely functional approach as well, but I've
> > been bitten several times by laziness causing space leaks in this
> > context. I'm on a bit of a time crunch for this, so I avoided the
> > risk.
> Well, space leaks won't magically disappear if you use  IO a .
> Regards,
> apfelmus

More information about the Haskell-Cafe mailing list