[Haskell-cafe] Category theory monad <----> Haskell monad

Michael Vanier mvanier at cs.caltech.edu
Fri Aug 19 01:47:42 EDT 2005

The explanation given below might be a bit heavy for someone who didn't know much
about category theory.  For those individuals I'd recommend Phil Wadler's


I especially recommend "Monads for Functional Programming", "The Essence of
Functional Programming" and "Comprehending Monads".

Basically, though, the Haskell implementation _is_ the category theoretic
definition of monad, with bind/return used instead of (f)map/join/return as
described below.


> Date: Thu, 18 Aug 2005 20:39:37 -0400
> From: Cale Gibbard <cgibbard at gmail.com>
> Cc: haskell-cafe at haskell.org
> On 14/08/05, Carl Marks <id2359 at yahoo.com> wrote:
> > Is there any text/article which makes precise/rigorous/explicit the connection
> > between the category theoretic definition of monad with the haskell
> > implementation?
> Well, a monad over a category C is an endofunctor T on C, together
> with a pair of natural transformations eta: 1 -> T, and mu: T^2 -> T
> such that
> 1) mu . (mu . T) = mu . (T . mu)
> 2) mu . (T . eta) = mu . (eta . T) = id_C
> In Haskell, a monad is an endofunctor on the category of all Haskell
> types and Haskell functions between them. Application of the
> endofunctor to an object is given by applying a type constructor (the
> one which is made an instance of the Monad class). Application of the
> endofunctor to a function is carried out by fmap or liftM. The natural
> transformation eta is called return, and mu is called join (found in
> the Monad library).
> Haskell uses a somewhat different (but equivalent) basis for a monad,
> in that it is not map, return, and join which need defining to make a
> type an instance of the Monad class, but return and (>>=), called
> "bind" or "extend".
> One can define bind in terms of fmap, and join as
> x >>= f = join (fmap f x)
> and one can get back join and fmap from return and bind:
> join x = x >>= id
> fmap f x = x >>= (return . f)
> hope this helps,
> - Cale
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list