
On Sun, Aug 22, 2010 at 9:45 AM, Johan Tibell
On Sat, Aug 21, 2010 at 1:45 PM, Ian Lynagh
wrote: On Wed, Aug 18, 2010 at 02:00:39PM +0200, Johan Tibell wrote:
The current API doesn't offer any efficient way to do something simple
as
e.g. summing the values in a map. I suggest we add a foldlWithKey' function:
Shouldn't (go z l) be forced too?
It makes sense to me to do so but the core looks worse for some reason:
foldlWithKey' :: (b -> k -> a -> b) -> b -> Map k a -> b foldlWithKey' f z0 m0 = go z0 m0 where go z _ | z `seq` False = undefined go z Tip = z go z (Bin _ kx x l r) = let z' = go z l z'' = f z' kx x
By the way, the problem remains if the unnecessary forcing of z'' is removed or the guard that forces z is removed.
in z' `seq` z'' `seq` go z'' r {-# INLINE foldlWithKey' #-}