[Haskell-cafe] Commutative monads vs Applicative functors

Olaf Klinke olf at aatal-apotheke.de
Sun Jul 10 20:57:23 UTC 2016

Anders Kock has a nice paper on commutative monads [1]. He relates 
commutativity to the Fubini theorem, because that is what commutativity 
is for the monad of meaures: You can change the order in integration by 
parts. He works in a symmetric monoidal closed category, so Hask works, 
too. It is the sort of category theory paper where you can go along the 
paper and implement most of it in Haskell. In particular, he mentions that 
MonadPlus has an alternative set of laws:
A monad m is a MonadPlus when there are isomorphisms

iso0 :: () -> m Void
iso2 :: (m a,m b) -> m (Either a b)

Indeed, let

mzero = liftM absurd (iso0 ())
mplus x y = liftM codiagonal (iso2 (x,y)) where
   codiagonal (Left x)  = x
   codiagonal (Right y) = y

Conversely, let

iso0 ()    = mzero
iso2 (x,y) = (liftM Left x) `mplus` (liftM Right y)

Then Kock shows that the MonadPlus operations are automatically 
Eilenberg-Moore algebra homomorphisms, which is the abstract way of saying 
that addition distributes over multiplication.

On a related note, I wonder whether the following is true:
Let m be a monad and let r be an object which is an m-algebra. Think of 
m as the free semigroup monad. Now consider the continuation monad

type T x = (x -> r) -> r

Observe that (x -> r) inherits the m-algebra structure of r. 
Let T' x be the subset of maps in T x which are m-linear. Is T' a monad, 
too? Can this me made concrete in a Haskell function?


[1] @article{kock12,
         author="Kock, Anders",
         title="Commutative monads as a theory of distributions",
         journal="Theory and Applications of Categories",

More information about the Haskell-Cafe mailing list