What is a monad?

Now we’ve seen a bit of motivation, it’s time to knuckle down and be specific. A monad on a category \mathcal{C}, referred to as the base category, has three components:

  1. An endofunctor \mathbb{T} : \mathcal{C} \rightarrow \mathcal{C}.
  2. A unit natural transformation \eta : \mathsf{Id} \Rightarrow \mathbb{T}.
  3. A multiplication natural transformation \mu : \mathbb{T}^2 \Rightarrow \mathbb{T}.

Furthermore, the unit and multiplication must satisfying the following axioms:

  • Left unitality: \mu \circ \eta_{\mathbb{T}} = \mathsf{id}.
  • Right unitality: \mu \circ \mathbb{T}\eta = \mathsf{id}.
  • Associativity: \mu \circ \mu_{\mathbb{T}} = \mu \circ \mathbb{T}\mu.

The names of the natural transformations and axioms reflect the fact that a monad is actually a monoid in a precise sense. To avoid pulling in lots of definitions to explain the details, we shall postpone discussing this point for now. Instead, we shall move straight to some standard examples:

  • On any category, the identity functor \mathsf{Id} : \mathcal{C} \rightarrow \mathcal{C} is a monad. Although this example is trivial, it is useful to have in mind, as this monad crops up in various constructions.
  • On any category with a terminal object, the functor mapping every object to the terminal object is a monad in a unique way.
  • On the category of sets and functions:
    • The functor \mathbb{L}, with \mathbb{L}(A) the set of lists of elements from A is a monad. The unit has \eta(a) = [a], and the multiplication concatenates a list-of-lists to a list.
    • The functor \mathbb{M}, with \mathbb{M}(A) the set of (finite) multisets or bags of elements from A. A multiset is a set in which elements can appear more than once. The unit maps an element to the corresponding singleton set, and the multiplication is given unions of multisets.
    • The functor~\mathbb{P} mapping a set to its finite powerset is a monad, in a similar way to the monad \mathbb{M}.
  • On any preorder A, a closure operator is a monotone function c such that a \leq c(a) and cc(a) = c(a). If we view A as a category, closure operators and monads on A are the same thing.

Also, we must point out a very important non-example:

  • If \mathbb{S} and \mathbb{T} are monads, the composite endofunctor \mathbb{T} \circ \mathbb{S} is not necessarily a monad.

The examples we have opened with are fairly standard, and commonly crop up in early discussion of monads. This is not because there is a shortage of monads out there, but rather that these examples don’t require any complex machinery or background knowledge.

Rather than just trying things and seeing if the monad axioms hold, it is natural to ask if there are more systematic ways of getting our hands on monads. This is the question we shall look at next.

4 thoughts on “What is a monad?”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: