Now we’ve seen a bit of motivation, it’s time to knuckle down and be specific. A monad on a category , referred to as the base category, has three components:
- An endofunctor .
- A unit natural transformation .
- A multiplication natural transformation .
Furthermore, the unit and multiplication must satisfying the following axioms:
- Left unitality: .
- Right unitality: .
- Associativity: .
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 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 , with the set of lists of elements from is a monad. The unit has , and the multiplication concatenates a list-of-lists to a list.
- The functor , with the set of (finite) multisets or bags of elements from . 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~ mapping a set to its finite powerset is a monad, in a similar way to the monad .
- On any preorder , a closure operator is a monotone function such that and . If we view as a category, closure operators and monads on are the same thing.
Also, we must point out a very important non-example:
- If and are monads, the composite endofunctor 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.