Proposal: Add a strict version of foldlWithKey to Data.Map
Johan Tibell
johan.tibell at gmail.com
Sun Aug 22 04:12:25 EDT 2010
On Sun, Aug 22, 2010 at 9:45 AM, Johan Tibell <johan.tibell at gmail.com>wrote:
> On Sat, Aug 21, 2010 at 1:45 PM, Ian Lynagh <igloo at earth.li> 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:
>> >
>> > http://hackage.haskell.org/trac/ghc/ticket/4261
>>
>> 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' #-}
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/libraries/attachments/20100822/e903a041/attachment.html
More information about the Libraries
mailing list