[Haskell-cafe] Foldable for (,)

Nickolay Kudasov nickolay.kudasov at gmail.com
Thu May 4 08:16:29 UTC 2017

Hi Jonathon,

Traversable instances do not change the shape of a data structure!

On the contrary, the whole purpose of traverse is to combine effectful
computations, stored in a structure without changing its shape! While
Foldable folds over the contents of a data structure (via Monoid),
Traversable allows you to fold over the effects attached to the contents of
that structure (via Applicative).

It turns out that by using Const applicative functor you can use traverse
to perform foldMap! Thus every Traversable is trivially a Foldable (see
Similarly, every Traversable is trivially a Functor if you use Identity
applicative functor (see fmapDefault).
This is why Traversable has those Functor and Foldable constraints, not
because it relies on fmap or foldMap.

Kind regards,

On Thu, 4 May 2017 at 10:49 Jonathon Delgado <voldermort at hotmail.com> wrote:

> It seems that Traversable is doing two things:
> 1) Changing the shape of a data structure.
> 2) Folding over the contents of a data structure.
> Traversable requires Foldable to enable 2, but Traversable is also applied
> to types such as (,) where only 1 is relevant.
> If this is correct, follow-up questions would be:
> 1) For educational purposes, could these concerns be split without
> substantial drawback?
> 2) For practical purposes, could this be done without breaking a lot of
> existing code?
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170504/b027d405/attachment-0001.html>

More information about the Haskell-Cafe mailing list