[Haskell-cafe] Non-traversable foldables
ekmett at gmail.com
Fri Oct 9 10:57:48 EDT 2009
On Fri, Oct 9, 2009 at 10:45 AM, Henning Thielemann <
lemming at 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.
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)
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe