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

David Banas capn.freako at gmail.com
Mon Mar 14 20:06:38 UTC 2016

Hi David,

Thanks so much for the two proposed exercises, and very sorry to have taken so long to respond to them.
I’ve constructed my responses in the form of an IHaskell notebook, and made that notebook available, here:



On Feb 5, 2016, at 11:20 AM, David Feuer <david.feuer at gmail.com> wrote:

> 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/20160314/69281ab5/attachment.html>

More information about the Haskell-Cafe mailing list