[Haskell-cafe] Non-traversable foldables
Edward Kmett
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.
>
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091009/45164e35/attachment.html
More information about the Haskell-Cafe
mailing list