[Haskell-cafe] Foldable/Traversable and Applicative/Monoid?

David Feuer david.feuer at gmail.com
Fri Feb 5 19:20:43 UTC 2016


It's not so much that it's *necessary* as that it's *possible*. The
existence of two functions in Data.Traversable explains both of the
superclasses of Traversable:

fmapDefault :: Traversable t => (a -> b) -> t a -> t b

foldMapDefault :: (Traversable t, Monoid m) => (a -> m) -> t a -> m

Each of these is written using only traverse, and they can be used to
define fmap and foldMap for types when you've written traverse.

Hint: Consider traversing using the following applicative functors:

newtype Const a b = Const a
instance Monoid a => Applicative (Const a)

newtype Identity a = Identity a
instance Applicative Identity
On Feb 5, 2016 1:45 PM, "David Banas" <capn.freako at gmail.com> wrote:

> Hi all,
>
> I don't understand why Foldable is a necessary super-class of Traversable,
> and I suspect that the Applicative/Monoid duality, which I've just begun
> discovering in the literature, has something to do with why that is so.
>
> Can anyone give me a hint, without giving me the answer?
>
> Thanks!
> -db
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160205/ee323901/attachment.html>


More information about the Haskell-Cafe mailing list