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

Johan Tibell johan.tibell at gmail.com
Wed Aug 18 09:04:03 EDT 2010


On Wed, Aug 18, 2010 at 2:47 PM, Ian Lynagh <igloo at earth.li> 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 (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.
>

I understand that f isn't strict in its first argument in general but in my
particular example it is, so why isn't it detected as such after f has been
inlined in go? If you manually inline f into go the problem remains.

Btw, this is using 6.12.2 in case that matters.

Cheers,
Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20100818/177bcdb9/attachment.html


More information about the Glasgow-haskell-users mailing list