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

Yitzchak Gale gale at sefer.org
Tue Nov 6 18:47:21 EST 2007

Hi Alex,

> I think I would have avoided most of the problems
> in the first place. I'm finding the documentation
> to be rather undiscoverable at the moment, but I'm
> sure it's just a question of learning my way around it.

Make sure to keep


on your favorites list.

>> Represent
>> your big iteration as a list. Try to stick
>> to fairly simple operations on the list. Then the
>> compiler will figure out how to keep things
>> lazy and also release memory as it goes along.

> See, this is what I thought I was doing, but I
> couldn't see where to simplify it further.

Sorry, you're right, I was begging the question.

Hmm. Well, for starters:

o Try to keep your big list far away from the IO monad.
o Whenever possible, use the following library
  functions rather than manual recursion for iterating over
  your big list: take, takeWhile, drop, dropWhile, map,
  concatMap, filter, zip, zipWith.

Browse around the wiki in places like:



More information about the Haskell-Cafe mailing list