Another space leak question

Alastair David Reid
02 Jul 2001 12:43:44 -0600

[Metacomment: the only way to really answer your question is to use
one of the debugging tools mentioned previously in the space leak
threads.  For large programs, anything else is just a list of

I think the space leak lies in the code you did not show us.

What does step look like?
If it looks like this:

  step (a,b,c) = (a',b',c') where ...

then the space leak is _not_ caused by bundling up the state - you
could move the take and drop inside the definition of step (which
would make your code a bit cleaner and more modular too.)

How do you access the list of helicopters inside step?
It could be that one of the random numbers you're asking for isn't being
evaluated and you're being left with a thunk like this:

  head randoms

where, in the first version of your code, randoms is an infinite list
and, in the second version, it is a small, finite list.

Maybe all you need to do is change the definition of step to:

  step (a,b,c) = c' `seq` (a',b',c') where ...

Finally, if this doesn't work (and debugging tools fail you) my
experience of arcade games in Haskell is that nearly all the state is
used to generate an image at each step.  If your problem is a
strictness bug, you might be able to find it just by thinking about
what parts of the state are _not_ used to generate the image.

Alastair Reid