[Haskell-cafe] Stack overflow

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Wed May 27 14:59:31 EDT 2009

I wrote:
> Krzysztof Skrzętnicki wrote:
>> The code for modifying the counter:
>> (\ msg -> atomicModifyIORef ioref (\ cnt -> (cntMsg cnt msg,())))
> atomicModifyIORef does not force the new value of the IORef.
> If the previous contents of the IORef is x, the new contents
> will be a thunk,
>   (\ cnt -> (cntMsg cnt msg,())) x

Sorry, it's slightly worse than that. The contents becomes

    sel_0 (\ cnt -> (cntMsg cnt msg, ())) x

where sel_0 is basically an RTS internal version of fst.

Instead of reading the new value of the IORef, you could also force the
old one:

    atomicModifyIORef ioref (\ cnt -> (cntMsg cnt msg, msg)) >>= (return $!)


More information about the Haskell-Cafe mailing list