<font face="verdana,sans-serif">Here&#39;s a version that works:<br><br><b>import Control.DeepSeq</b><br></font><br><div><div>list = [1,2,3,4,5]</div><div><br></div><div>advance l = <b>force $</b> map (\x -&gt; x+1) l</div>

<div><br></div><div>run 0 s = s</div><div>run n s = run (n-1) $ advance s</div><div><br></div><div>main = do</div><div>        let s =  run 50000000 list</div><div>        putStrLn $ show s<br><br>The problem is that you build of a huge chain of updates to the list. If we just &quot;commit&quot; each update as it happens, we&#39;ll use a constant amount of memory.<br>

<br>Haskell&#39;s laziness is tricky to understand coming from imperative languages, but once you figure out its evaluation rules, you&#39;ll begin to see the elegance.<br><br>Ηope this helps,<br>  - Clark<br></div></div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 28, 2012 at 7:07 AM, Benjamin Edwards <span dir="ltr">&lt;<a href="mailto:edwards.benj@gmail.com" target="_blank">edwards.benj@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">TCO + strictnesses annotations should take care of your problem.</p>
<div class="gmail_quote"><div><div class="h5">On 28 Nov 2012 11:44, &quot;Branimir Maksimovic&quot; &lt;<a href="mailto:bmaxa@hotmail.com" target="_blank">bmaxa@hotmail.com</a>&gt; wrote:<br type="attribution"></div></div>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">



<div><div dir="ltr">
Problem is following short program:<div><div>list = [1,2,3,4,5]</div><div><br></div><div>advance l = map (\x -&gt; x+1) l</div><div><br></div><div>run 0 s = s</div><div>run n s = run (n-1) $ advance s</div><div><br></div>


<div>main = do</div><div>        let s =  run 50000000 list</div><div>        putStrLn $ show s</div></div><div><br></div><div>I want to incrementally update list lot of times, but don&#39;t know</div><div>how to do this.</div>


<div>Since Haskell does not have loops I have to use recursion,</div><div>but problem is that recursive calls keep previous/state parameter</div><div>leading to excessive stack.and memory usage.</div><div>I don&#39;t know how to tell Haskell not to keep previous</div>


<div>state rather to release so memory consumption becomes</div><div>managable.</div><div><br></div><div>Is there some solution to this problem as I think it is rather</div><div>common?</div><div><br></div>                                               </div>


</div>
<br></div></div>_______________________________________________<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>
<br></blockquote></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">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>
<br></blockquote></div><br></div>