<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Thank you very much! That solved it ;)<div>I had to put explicit type signature in front of advance in order to compile</div><div><br><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">From: cgaebel@uwaterloo.ca<br>Date: Wed, 28 Nov 2012 08:01:38 -0500<br>Subject: Re: [Haskell-cafe] How to incrementally update list<br>To: edwards.benj@gmail.com<br>CC: bmaxa@hotmail.com; haskell-cafe@haskell.org<br><br><font face="verdana,sans-serif">Here'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>&nbsp; &nbsp; &nbsp; &nbsp; let s = &nbsp;run 50000000 list</div><div>&nbsp; &nbsp; &nbsp; &nbsp; putStrLn $ show s<br><br>The problem is that you build of a huge chain of updates to the list. If we just "commit" each update as it happens, we'll use a constant amount of memory.<br>

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

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

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

<blockquote class="ecxgmail_quote" style="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>&nbsp; &nbsp; &nbsp; &nbsp; let s = &nbsp;run 50000000 list</div><div>&nbsp; &nbsp; &nbsp; &nbsp; putStrLn $ show s</div></div><div><br></div><div>I want to incrementally update list lot of times, but don'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't know how to tell Haskell not to keep previous</div>


<div>state rather to release so memory&nbsp;consumption&nbsp;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">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></div></div>                                               </div></body>
</html>