[Haskell-beginners] Brainfuck interpreter stack overflow

Daniel Fischer daniel.is.fischer at web.de
Thu Jan 21 07:06:54 EST 2010

Am Mittwoch 20 Januar 2010 16:45:41 schrieb Edgar Klerks:
> Hello,
> I just started using haskell and found it many uses for it (mainly for
> scripting purposes at the moment). Now, I have written a brainfuck
> parser and interpreter in haskell, but it produces a stack overflow if
> the program runs too long and I don't understand why. I thought I made
> the interpreter loop tail recursive, which I understood is the most
> common cause of a stack overflow. Can someone help my find my fault? I
> somehow miss something. I added the program as attachment.
> Thanks for your help.
> With kind regards,
> Edgar Klerks

A quick look revealed that you use Control.Monad.State, which defaults to 
Control.Monad.State.Lazy. That is very often too lazy for longer 
calculations and produces a stack overflow.
Maybe changing the import to Control.Monad.State.Strict helps (that isn't 
entirely strict either, but often reduces the opportunities for building 
large thunks sufficiently).

More information about the Beginners mailing list