[Haskell-cafe] ST not strict enough?

Jason Dusek jason.dusek at gmail.com
Fri Nov 18 05:57:34 CET 2011


2011/11/16 Johan Tibell <johan.tibell at gmail.com>:
> On Wed, Nov 16, 2011 at 2:23 PM, Jason Dusek <jason.dusek at gmail.com> wrote:
>> 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).

I just didn't want to miss an opportunity to put in extra
strictness annotations! School of redundancy school.

--
Jason Dusek
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments



More information about the Haskell-Cafe mailing list