[Haskell-cafe] Monte Carlo Pi calculation (newbie learnings)

David Benbennick dbenbenn at gmail.com
Mon Nov 5 16:43:16 EST 2007


On 11/5/07, David Roundy <droundy at darcs.net> wrote:
> On Mon, Nov 05, 2007 at 01:42:50PM -0700, Luke Palmer wrote:
> > 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)

Or even better, have a declaration

instance (Random a, Random b) => Random (a, b)

then do

let pairs = randomRs ((-1, -1), (1, 1)) g0

Wouldn't it be nice if System.Random had an instance declaration for pairs?


More information about the Haskell-Cafe mailing list