[Haskell-cafe] Stack overflow while programming imperatively

Clark Gaebel cgaebel at csclub.uwaterloo.ca
Sun Mar 18 20:32:57 CET 2012

Yay, that fixed it. Thanks!

On Sun, Mar 18, 2012 at 2:50 PM, Aleksey Khudyakov
<alexey.skladnoy at gmail.com> wrote:
> On 18.03.2012 22:32, Clark Gaebel wrote:
>> Hey list.
>> I was recently fixing a space leak by dropping down to imperative
>> programming in a section of my code, when it started developing space
>> leaks of its own.
>> I found the problem though - it was my "for loop": http://hpaste.org/65514
>> Can anyone provide suggestions on why that stack overflows? It seems
>> ridiculously tail recursive. I tried to do it more haskell-like with
>> http://hpaste.org/65517, but it was still spending 75% of its time in
>> GC.
> Excessive laziness could be cleverly hiding. modifyIORef doesn't modify
> IORef's value but builds huge chain of thunks. When you try to evaluate
> it you get stack overflow. Forcing value of IORef will fix this space leak.
> You could use strict version of modifyIORef:
> modifyIORef' x f = do
>  a <- readIORef x
>  writeIORef x $! f a
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list