
Hallo café, Can anyone think of datatypes that are Foldable but not Traversable? If not, what is the purpose of having a separate Foldable class? Thanks, Martijn.

On Fri, 9 Oct 2009, Martijn van Steenbergen wrote:
Hallo café,
Can anyone think of datatypes that are Foldable but not Traversable?
If not, what is the purpose of having a separate Foldable class?
Recently I wondered, why Foldable is superclass of Traversable, since I have examples where 'traverse' makes sense, but 'fold' not. http://www.haskell.org/pipermail/libraries/2009-February/011361.html

On Fri, Oct 9, 2009 at 10:45 AM, Henning Thielemann < lemming@henning-thielemann.de> wrote:
On Fri, 9 Oct 2009, Martijn van Steenbergen wrote:
Hallo café,
Can anyone think of datatypes that are Foldable but not Traversable?
Data.Set.Set is a good example. The values contained in the Set are critical to the well-formedness of the data structure. Foldables let you iterate over a container while preserving structure, Traversables allow you to swap out the contents, but preserve the existing structure. Since you can do that you get fmap for free.
If not, what is the purpose of having a separate Foldable class?
Recently I wondered, why Foldable is superclass of Traversable, since I have examples where 'traverse' makes sense, but 'fold' not.
http://www.haskell.org/pipermail/libraries/2009-February/011361.html
The superclass is there simply because there is a free implementation of foldMap (and fmap) given a Traversable instance, and it is useful to have access to all of those methods without building up a big long dictionary list, or having to clone them to make Traversable-specific versions) -Edward
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Fri, Oct 09, 2009 at 04:45:01PM +0200, Henning Thielemann wrote:
Recently I wondered, why Foldable is superclass of Traversable, since I have examples where 'traverse' makes sense, but 'fold' not.
http://www.haskell.org/pipermail/libraries/2009-February/011361.html
That would be surprising, since fold can be defined in terms of traverse. The link doesn't seem to contain any such examples.
participants (4)
-
Edward Kmett
-
Henning Thielemann
-
Martijn van Steenbergen
-
Ross Paterson