Is it not:<br><br>&gt; noLeak :: State Int ()<br>
&gt; noLeak = do<br>
&gt;   a &lt;- get<br>
<b>&gt;</b>  <b> let a&#39; = (a + 1)<br>
&gt;   a&#39; `seq` put a&#39;</b><br>
&gt;   noLeak<br><br>??<br><br><div class="gmail_quote">2011/6/9 Alexey Khudyakov <span dir="ltr">&lt;<a href="mailto:alexey.skladnoy@gmail.com">alexey.skladnoy@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hello café!<br>
<br>
This mail is literate haskell<br>
<br>
I have some difficulties with understanding how bang patterns and seq<br>
works.<br>
<br>
&gt; {-# LANGUAGE BangPatterns #-}<br>
&gt; import Control.Monad<br>
&gt; import Control.Monad.Trans.State.Strict<br>
&gt;<br>
&gt; leak :: State Int ()<br>
&gt; leak = do<br>
&gt;   a &lt;- get<br>
&gt;   put (a+1)<br>
&gt;   leak<br>
<br>
This function have obvious space leak. It builds huge chain of thunks<br>
so callling `runState leak 0&#39; in ghci will eat all memory. Fix is trivial - add bang pattern. However I couldn&#39;t achieve same<br>
effect with seq. How could it be done?<br>
<br>
&gt; noLeak :: State Int ()<br>
&gt; noLeak = do<br>
&gt;   a &lt;- get<br>
&gt;   let !a&#39; = (a + 1)<br>
&gt;   put a&#39;<br>
&gt;   noLeak<br>
<br>
<br>
Thanks.<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>