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

2010-08-18 Thread Johan Tibell
On Wed, Aug 18, 2010 at 4:38 PM, Lennart Augustsson < lennart.augusts...@gmail.com> wrote: > You don't know that f is strict in its first argument so you cannot > deduce that go is strict in z in the first case. > I'm not sure I understand. f :: Int -> Int -> Int -> Int f = \x y z -> x + y + z

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

2010-08-18 Thread Johan Tibell
On Wed, Aug 18, 2010 at 2:47 PM, Ian Lynagh wrote: > 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 (Bi

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

2010-08-18 Thread Ian Lynagh
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 > > C

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

2010-08-18 Thread Johan Tibell
Hi, I was adding a strict pre-order fold to the Data.Map module and I ran into this slightly surprising behavior. Modeled on foldl' for lists I defined foldlWithKey' :: (b -> k -> a -> b) -> b -> Map k a -> b foldlWithKey' f z0 m = go z0 m where go z Tip = z