[Haskell-beginners] Brainfuck interpreter stack overflow

Edgar Klerks edgar at goodforall.eu
Thu Jan 21 08:33:31 EST 2010

He Daniel,

Cool, I just found out the same with the profiler. I have removed the state
entirely (it is not really neccesary) and it results in a speedup of 10x.
Storing the instructions in an array instead of an list speeded also things

But I will test the original with State.Strict and see how it will perform.



2010/1/21 Daniel Fischer <daniel.is.fischer at web.de>

> 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).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100121/c55c9688/attachment.html

More information about the Beginners mailing list