On Wed, Nov 16, 2011 at 2:23 PM, Jason Dusek <jason.dusek@gmail.com> wrote:
> Just double checked. modifySTRef is too lazy:
> -- |Mutate the contents of an 'STRef'
> modifySTRef :: STRef s a -> (a -> a) -> ST s ()
> modifySTRef ref f = writeSTRef ref . f =<< readSTRef ref
> We need Data.STRef.Strict

Tried a modifySTRef' defined this way:

modifySTRef' ref f           =  do
 val                       <-  (f $!!) <$> readSTRef ref
 writeSTRef ref (val `seq` val)

...but there was no change in memory usage.

Why not just

    modifySTRef :: STRef s a -> (a -> a) -> ST s ()
    modifySTRef ref f = do
        x <- readSTRef ref
        writeSTRef ref $! f x 

(Note that I didn't check if modifySTRef was actually a problem in this case).

-- Johan