[Haskell-cafe] Swapping Monads

Derek Elkins derek.a.elkins at gmail.com
Tue Jul 8 09:59:01 EDT 2008


On Tue, 2008-07-08 at 06:39 +0100, Dominic Steinitz wrote:
> I have a solution so this is for interest only.
> 
> It is not normally the case that two monads compose to give another
> monad. Monad transformers capture when this is possible. However, when
> there is a "swap" function satisfying some commutative diagrams then it
> can be proved that the monads compose  to produce a monad.
> 
> Is there such a swap function in a library? I had a look in the
> comprehensive category-extra package but couldn't find anything.

You didn't look hard enough.  What you want is called a distributive law
in category theory.  A class for exactly what you want is in
Control.Functor.Extras.

http://hackage.haskell.org/packages/archive/category-extras/0.53.5/doc/html/Control-Functor-Extras.html#t%3ADistributes



More information about the Haskell-Cafe mailing list