On Wed, Nov 16, 2011 at 12:07 PM, Johan Tibell <span dir="ltr">&lt;<a href="mailto:johan.tibell@gmail.com">johan.tibell@gmail.com</a>&gt;</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">On Wed, Nov 16, 2011 at 11:58 AM, Jason Dusek <span dir="ltr">&lt;<a href="mailto:jason.dusek@gmail.com" target="_blank">jason.dusek@gmail.com</a>&gt;</span> wrote:</div><div class="gmail_quote"><div class="im">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
diff --git a/Rebuild.hs b/Rebuild.hs<br>
@@ -15,6 +15,7 @@ import Data.STRef<br>
 import Data.String<br>
 import Data.Word<br>
<br>
+import Control.DeepSeq<br>
 import Data.Vector.Unboxed (Vector)<br>
 import qualified Data.Vector.Unboxed as Vector (create, length)<br>
 import qualified Data.Vector.Unboxed.Mutable as Vector hiding (length)<br>
@@ -46,8 +47,8 @@ rebuildAsVector bytes        =  byteVector<br>
     n                       &lt;-  readSTRef counter<br>
     return (Vector.unsafeSlice 0 n v)<br>
   writeOneByte v counter b   =  do n &lt;- readSTRef counter<br>
-                                   Vector.unsafeWrite v n b<br>
+                                   w v n b<br>
                                    modifySTRef counter (+!1)<br>
+  (+!) a b                   =  ((+) $!! a) $!! b<br>
+  w v n b = (Vector.unsafeWrite v $!! n) $!! b<br></blockquote><div><br></div></div><div>+! doesn&#39;t work unless modifySTRef is already strict in the result of the function application. You need to write modifySTRef&#39; that seq:s the result of the function application before calling writeSTRef.</div>

</div></blockquote><div><br></div><div>Just double checked. modifySTRef is too lazy:</div><div><br></div><div>-- |Mutate the contents of an &#39;STRef&#39;</div><div>modifySTRef :: STRef s a -&gt; (a -&gt; a) -&gt; ST s ()</div>

<div>modifySTRef ref f = writeSTRef ref . f =&lt;&lt; readSTRef ref</div><div><br></div><div>We need Data.STRef.Strict</div></div>