[Haskell-cafe] Monte Carlo Pi calculation (newbie learnings)
Luke Palmer
lrpalmer at gmail.com
Mon Nov 5 15:42:50 EST 2007
On Nov 5, 2007 1:30 PM, Jonathan Cast <jonathanccast at fastmail.fm> wrote:
> > main = do
>
> Get two standard generators (one per dimension)
>
> > g0 <- newStdGen
> > g1 <- newStdGen
>
> 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 ]
(Did I remember that syntax right?)
Luke
More information about the Haskell-Cafe
mailing list