[Haskell-cafe] A Proposed Law for Foldable?

David Feuer david.feuer at gmail.com
Fri Feb 27 23:43:05 UTC 2015


Suppose you convince me that hiding elements from foldMap is bad (I'm easy
to persuade!). There is still, I believe, a much more serious problem.
Specifically, you claim that your new law somehow takes care of potentially
infinite containers, but I do not see how it does. Consider, for example,
the instance for Data.Tree.Tree:

data Tree a = Node { rootLabel :: a, -- ^ label value
                    subForest :: Forest a -- ^ zero or more child trees
                    }

instance Foldable Tree where
  foldMap f (Node x ts) = f x `mappend` foldMap (foldMap f) ts

If the first child of the root is an infinite tree, your search will never
reach the root of the second child! Generally, foldMap on any potentially
infinite tree will be forced to work (at least approximately) breadth-first.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150227/fb7bde9c/attachment.html>


More information about the Libraries mailing list