Very informative. The list is in the heap but the lazy sum of foldl  is in the stack. ok.<div><div>I suppose that all tail recursive functions are detected by the strictness analysis.</div><div><br></div><div><div class="gmail_quote">
2009/6/18 Chaddaï Fouché <span dir="ltr">&lt;<a href="mailto:chaddai.fouche@gmail.com">chaddai.fouche@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Thu, Jun 18, 2009 at 6:38 PM, Alberto G. Corona&lt;<a href="mailto:agocorona@gmail.com">agocorona@gmail.com</a>&gt; wrote:<br>
&gt; My question is: Why the process does not grow aleso in the lazy case and<br>
&gt; instead produces a stack overflow inmediately?<br>
<br>
</div>This question is answered in detail on the Wiki<br>
<a href="http://www.haskell.org/haskellwiki/Foldr_Foldl_Foldl%27" target="_blank">http://www.haskell.org/haskellwiki/Foldr_Foldl_Foldl%27</a><br>
As you thought, it is not the evaluation of foldl that overflow the<br>
stack, since foldl is terminally recursive it won&#39;t ever overflow the<br>
stack. On the other hand when the thunk created by foldl is finally<br>
evaluated, if the argument function is strict in its first argument it<br>
will overflow the stack if the list was too long.<br>
<br>
It is important to note that the size of the list itself or even the<br>
thunk doesn&#39;t guarantee a stack overflow : both of those structure are<br>
in the heap and if the argument function can produce output before<br>
evaluating its first argument, there will be no stack overflow,<br>
whatever the size of the thunk.<br>
<br>
As evidenced by this expression :<br>
ghci&gt; take 10 . foldl (flip (:)) [] $ [1..1000000]<br>
[1000000,999999,999998,999997,999996,999995,999994,999993,999992,999991]<br>
<font color="#888888"><br>
--<br>
Jedaï<br>
</font></blockquote></div><br></div></div>