On Wed, Nov 16, 2011 at 2:23 PM, Jason Dusek <span dir="ltr"><<a href="mailto:jason.dusek@gmail.com">jason.dusek@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">> Just double checked. modifySTRef is too lazy:<br>
> -- |Mutate the contents of an 'STRef'<br>
> modifySTRef :: STRef s a -> (a -> a) -> ST s ()<br>
> modifySTRef ref f = writeSTRef ref . f =<< readSTRef ref<br>
> We need Data.STRef.Strict<br>
<br>
</div>Tried a modifySTRef' defined this way:<br>
<br>
modifySTRef' ref f = do<br>
val <- (f $!!) <$> readSTRef ref<br>
writeSTRef ref (val `seq` val)<br>
<br>
...but there was no change in memory usage.</blockquote><div><br></div><div>Why not just</div><div><br></div><div> modifySTRef :: STRef s a -> (a -> a) -> ST s ()</div> modifySTRef ref f = do</div><div class="gmail_quote">
x <- readSTRef ref</div><div class="gmail_quote"> writeSTRef ref $! f x </div><div class="gmail_quote"><br></div><div class="gmail_quote">(Note that I didn't check if modifySTRef was actually a problem in this case).</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">-- Johan</div><div class="gmail_quote"><br></div>