<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">18.09.2012, 16:32, &quot;Jan Stolarek&quot; &lt;<a href="mailto:jan.stolarek@p.lodz.pl">jan.stolarek@p.lodz.pl</a>&gt;:<br>

<div class="HOEnZb"><div class="h5">&gt; Hi list,<br>
&gt;<br>
&gt; I have yet another question about folds. Reading here and there I encountered statements that<br>
&gt; foldr is more important than foldl, e.g. in this post on the list:<br>
&gt; <a href="http://www.haskell.org/pipermail/haskell-cafe/2012-May/101338.html" target="_blank">http://www.haskell.org/pipermail/haskell-cafe/2012-May/101338.html</a><span onmouseout="cancel = false; window.setTimeout(WRCHideContent, 1000); clearTimeout(showTimer);" onmouseover=" var self = this; showTimer = window.setTimeout(function(){WRCShowContent({&#39;rating&#39;:{&#39;value&#39;:99,&#39;weight&#39;:14},&#39;flags&#39;:{},&#39;single&#39;:true,&#39;ttl&#39;:7200,&#39;expireTime&#39;:&#39;20120918013022&#39;}, self.className)},600);" class="wrc11" style="padding-right:16px;width:16px;height:16px"></span><br>

&gt; I want to know are such statements correct and, if so, why? I am aware that foldl&#39; can in some<br>
&gt; circumstances operate in constant space, while foldr can operate on infinite lists if the folding<br>
&gt; function is lazy in the second parameter. Is there more to this subject?<br></div></div></blockquote></div><br>Basically the difference is that foldr is really the natural catamorphism for the list type, that is for a type like :<br>
<br>data MyType = Zero | One A | Two B C | Recurse MyType<br><br>the natural catamorphism is a function that takes four arguments by which it will replace the four constructor so as to deconstruct a value of MyType :<br><br>
myTypeCata :: r -&gt; (A -&gt; r) -&gt; (B -&gt; C -&gt; r) -&gt; (r -&gt; r)   -&gt;    (MyType -&gt; r)<br>myTypeCata z o t re Zero = z<br>myTypeCata z o t re (One a) = o a<br>myTypeCata z o t re (Two b c) = t b c<br>myTypeCata z o t re (Recurse myType) = re (myTypeCata z o t re myType)<br>
<br>So foldr is the natural catamorphism for the list type and foldl is not.<br><br>-- <br>Jedaï<br>