[Haskell-cafe] Monte Carlo Pi calculation (newbie learnings)
David Roundy
droundy at darcs.net
Mon Nov 5 16:04:47 EST 2007
On Mon, Nov 05, 2007 at 01:42:50PM -0700, Luke Palmer wrote:
> On Nov 5, 2007 1:30 PM, Jonathan Cast <jonathanccast at fastmail.fm> wrote:
> > Get an infinite list of pairs
> >
> > > let pairs = [ (x, y) | x <- randoms (-1, 1) g0,
> > > y <- randoms (-1, 1) g1 ]
>
> This will return a list like [(a,b),(a,c),(a,d),(a,e),...]. This
> needs to be a parallel comprehension:
>
> let pairs = [ (x,y) | x <- randoms (-1,1) g0 | y <- randoms (-1,1) g1 ]
Or even better, just don't use list comprehensions, they're confusing:
let pairs = zip (randoms (-1,1) g0) (randoms (-1,1) g1)
Now you don't have to think backwards to figure out what the comprehension
is doing.
--
David Roundy
Department of Physics
Oregon State University
More information about the Haskell-Cafe
mailing list