apfelmus apfelmus at quantentunnel.de
Sun Dec 16 07:49:49 EST 2007

```Dan Weston wrote:
> newtype O f g a = O (f (g a))   -- Functor composition:  f `O` g
>
> instance (Functor f, Functor g) => Functor (O f g) where ...
> instance Adjunction f g         => Monad   (O g f) where ...
> instance Adjunction f g         => Comonad (O f g) where ...
>
> class (Functor f, Functor g) => Adjunction f g | f -> g, g -> f where
>   leftAdjunct  :: (f a -> b) -> a -> g b
>   rightAdjunct :: (a -> g b) -> f a -> b
> ----------------------------------------------------------
>
> Functors are associative but not generally commutative. Apparently a
> that commute.

Yes, but that's only sufficient, not necessary.

Jules and David already pointed out that while every monad comes from an

[] ~= g `O` f

or

>> data L a = One a | Cons a (L a)   -- non-empty list

L ~= g `O` f

(proof?) Yet, both are monads and the latter is even a comonad.

Moreover, f and g can only commute if they have the same source and
target category (Hask in our case). And even when they don't commute,

> My category theory study stopped somewhere between Functor and
> Adjunction, but is there any deep magic you can describe here in a
> paragraph or two? I feel like I will never get Monad and Comonad until I

Alas, I wish I could, but I have virtually no clue about adjoint
functors myself :)

I only know the classic example that conjunction and implication

f a = (a,S)
g b = S -> b

(a,S) -> b  =  a -> (S -> b)

which is just well-known currying. We get the state monad

(g `O` f) a = S -> (S,a)