Surprising strictness properties of pre-order fold over a Data.Map

Ian Lynagh igloo at earth.li
Wed Aug 18 08:47:08 EDT 2010


On Wed, Aug 18, 2010 at 12:01:54PM +0200, Johan Tibell wrote:
> 
>     foldlWithKey' :: (b -> k -> a -> b) -> b -> Map k a -> b
>     foldlWithKey' f z0 m = go z0 m
>       where
>         go z Tip              = z
>         go z (Bin _ kx x l r) = let x' = f (go z l) kx x in x' `seq` go x' r
>
> Could someone please explain the difference. I would like to be able
> to to understand when I would get the former or the latter by looking
> at the Haskell source.

If f is not strict in its first argument (e.g. if it always ignore it)
then go is not strict in z.


Thanks
Ian



More information about the Glasgow-haskell-users mailing list