[Haskell-cafe] Stack overflow

Tim Docker twd2 at dockerz.net
Wed May 27 23:08:32 EDT 2009

> Thanks for the tip, although it seems tricky to get it right. I wonder
> why there is no strict version of atomicModifyIORef?
> Dually there might be a strict version of IORef datatype.

Alternatively, you could use STM, where you can write your own atomic
update function, which has the strictness you need (untested):

import Control.Concurrent.STM

strictUpdate :: (a->a) -> TVar a -> STM ()
strictUpdate f v = do
    x <- readTVar v
    let x1 = f x
    x1 `seq` writeTVar v x1

g :: (Int->Int) -> TVar Int -> IO ()
g f v = atomically (strictUpdate f v)


More information about the Haskell-Cafe mailing list