[Haskell-cafe] ST not strict enough?
Jason Dusek
jason.dusek at gmail.com
Wed Nov 16 23:23:39 CET 2011
2011/11/16 Johan Tibell <johan.tibell at gmail.com>:
> On Wed, Nov 16, 2011 at 12:07 PM, Johan Tibell <johan.tibell at gmail.com> 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
More information about the Haskell-Cafe
mailing list