On Sun, Aug 22, 2010 at 9:45 AM, Johan Tibell <span dir="ltr"><<a href="mailto:johan.tibell@gmail.com">johan.tibell@gmail.com</a>></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"><<a href="mailto:igloo@earth.li" target="_blank">igloo@earth.li</a>></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>
><br>
> The current API doesn't offer any efficient way to do something simple as<br>
> e.g. summing the values in a map. I suggest we add a foldlWithKey' function:<br>
><br>
> <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'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' :: (b -> k -> a -> b) -> b -> Map k a -> b</div>
<div> foldlWithKey' 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' = go z l</div>
<div> z'' = f z' kx x</div></div></blockquote><div><br></div><div>By the way, the problem remains if the unnecessary forcing of z'' 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' `seq` z'' `seq` go z'' r</div>
<div> {-# INLINE foldlWithKey' #-}</div></div></blockquote><div> </div></div>