On Sun, Aug 22, 2010 at 9:45 AM, Johan Tibell <span dir="ltr">&lt;<a href="mailto:johan.tibell@gmail.com">johan.tibell@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div><div></div><div class="h5">On Sat, Aug 21, 2010 at 1:45 PM, Ian Lynagh <span dir="ltr">&lt;<a href="mailto:igloo@earth.li" target="_blank">igloo@earth.li</a>&gt;</span> wrote:<br></div></div><div class="gmail_quote">

<div><div></div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Wed, Aug 18, 2010 at 02:00:39PM +0200, Johan Tibell wrote:<br>
&gt;<br>
&gt; The current API doesn&#39;t offer any efficient way to do something simple as<br>
&gt; e.g. summing the values in a map. I suggest we add a foldlWithKey&#39; function:<br>
&gt;<br>
&gt;     <a href="http://hackage.haskell.org/trac/ghc/ticket/4261" target="_blank">http://hackage.haskell.org/trac/ghc/ticket/4261</a><br>
<br>
</div>Shouldn&#39;t (go z l) be forced too?<br></blockquote><div><br></div></div></div><div>It makes sense to me to do so but the core looks worse for some reason:</div><div><br></div><div>    foldlWithKey&#39; :: (b -&gt; k -&gt; a -&gt; b) -&gt; b -&gt; Map k a -&gt; b</div>


<div>    foldlWithKey&#39; f z0 m0 = go z0 m0</div><div>      where</div><div>        go z _ | z `seq` False = undefined</div><div>        go z Tip               = z</div><div>        go z (Bin _ kx x l r)  = let z&#39;  = go z l</div>


<div>                                     z&#39;&#39; = f z&#39; kx x</div></div></blockquote><div><br></div><div>By the way, the problem remains if the unnecessary forcing of z&#39;&#39; is removed or the guard that forces z is removed.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div>                                 in z&#39; `seq` z&#39;&#39; `seq` go z&#39;&#39; r</div>

<div>    {-# INLINE foldlWithKey&#39; #-}</div></div></blockquote><div> </div></div>