<div class="gmail_quote">On Mon, Aug 23, 2010 at 11:40 AM, Gregory Collins <span dir="ltr">&lt;<a href="mailto:greg@gregorycollins.net">greg@gregorycollins.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<div class="im">Johan Tibell &lt;<a href="mailto:johan.tibell@gmail.com">johan.tibell@gmail.com</a>&gt; writes:<br>
<br>
&gt; It&#39;s not true that<br>
&gt;<br>
&gt;     fold f z == foldr f z . elems<br>
&gt;<br>
&gt; in general. It only holds if `z` is an identity for `f` as `z` is used<br>
&gt; at every leaf in the tree.<br>
<br>
</div>Hey Johan,<br>
<br>
    -- | /O(n)/. Post-order fold.<br>
    foldr :: (k -&gt; a -&gt; b -&gt; b) -&gt; b -&gt; Map k a -&gt; b<br>
    foldr _ z Tip              = z<br>
    foldr f z (Bin _ kx x l r) = foldr f (f kx x (foldr f z r)) l<br>
<br>
Note the third parameter to the recursive foldr call -- the &quot;z&quot; you see<br>
at the Tips is not the same &quot;z&quot; that was originally passed in.<br></blockquote></div><br>You&#39;re of course right. I can get back to my optimizing. :)<br><br>