
2011/11/16 Johan Tibell
On Wed, Nov 16, 2011 at 12:07 PM, Johan Tibell
wrote: +! doesn't work unless modifySTRef is already strict in the result of the function application. You need to write modifySTRef' that seq:s the result of the function application before calling writeSTRef.
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. -- Jason Dusek () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments