[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    [Haskell-cafe] Re: Haskell-Cafe Digest, Vol 47, Issue 237
From:       "Chad Scherrer" <chad.scherrer () gmail ! com>
Date:       2007-07-31 18:10:32
Message-ID: fe9a19910707311110r5a7ce1d7u17d27bac181612c5 () mail ! gmail ! com
[Download RAW message or body]

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.

Thanks,
Chad

> 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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic