[Haskell-beginners] SOLVED - Stack overflow, but hard to understand

Magnus Therning magnus at therning.org
Wed Oct 21 01:38:01 EDT 2009

On 20/10/09 20:32, Michael Mossey wrote:
> Okay, I figured this out. mapM is not lazy, at least not for a monad that
> has state and under the circumstance you demand the state out the other
> side.

If I understand what you are saying then this behaviour isn't unexpected.  If
you have a monad with state, and you ask for the final state, then it's likely
that everything happening in that particular monad will has to be evaluated.

> I may rewrite the program. Or I may consider the ISS principle.
> ("Increase the stack, stupid.")

You may also be able to improve the situation by adding a bit of strictness.
In some cases the thunks resulting from laziness can take up a lot of space.
Forcing evaluation, at well thought out locations in your program, may both
speed things up and reduce memory/stack usage.


Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe

More information about the Beginners mailing list