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:

https://htmlpreview.github.io/?https://github.com/capn-freako/Haskell_Misc/blob/master/Applicative_Monoid_traverse_foldMap.html#davids_proposed_exercises

Thanks,
-db

On Feb 5, 2016, at 11:20 AM, David Feuer <david.feuer@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@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@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe