Haskell/Solutions/Traversable

Functors made for walking
1.

Interpretations of
1.

Note that this  behaves differently from the one in. That one will happily assemble columns of unequal length when given rows of unequal size, while our version cuts off extra elements. Neither solution is a very good one, but then nested lists are not a good representation for matrices in first place.

2.

is a  function which monoidally appends its argument to all of the values in. The relevant  instance is the one for functions.

3.

This is the type of :

With a couple flips, the type becomes...

... which is equivalent to:

That strongly suggests we can write  as a traversal with the   applicative functor. One important issue to consider is how the applicative instance of  sequences effects (for   is not commutative). Since we know that instances in the libraries sequence from left to right, we are good to go (otherwise, we would have to use to avoid ending up with  ).

.. and that's it. All that is needed is undoing the flips and adding the /  boilerplate.

That is just like the actual implementation in. The only difference is that  uses an internal implementation of   to avoid importing   (actually two implementations, thanks to the sequencing of effects issue).