Given a category and a functor , can you merely by inspecting the definition of conclude that admits the structure of a monad?
In some cases, you can. One way is to realize that can be decomposed into a composition of two adjoint functors and apply a well-known theorem. Presumably, checking that the functors are adjoint should be less work than defining the unit and multiplication directly and checking that they satisfy the monad laws.
For example, the state monad with state object on a cartesian closed category is given by . One sees immediately that arises from the adjunction , which expresses the fact is closed.
Another way is to realize that is the image of a monoid in a monoidal category under a lax monoidal functor . The goal of this post is to explain and illustrate by examples what this means.
A monoidal category is a category equipped with a bifunctor , called the tensor product, that is associative up to a natural isomorphism , and an object , called the unit object, that is both a left and right identity for , again up to natural isomorphisms and . The natural isomorphisms , , and are subject to two coherence conditions: a commutative pentagon, whose vertices correspond to the five possible ways to parenthesize the tensor product , and a commutative triangle, whose vertices are , , and .
For example, a cartesian category is naturally a monoidal category: the tensor product is the cartesian product and the unit object is the terminal object .
Another interesting example of monoidal category is the category of endofunctors on a category : the tensor product is the composition of functors and the unit object is the identity functor. The category is an example of strict monoidal category, i.e., one in which the natural associativity and identity isomorphisms are identity transformations.
The definition of monoid can be given relative to any monoidal category . A monoid in is an object equipped with a morphism , called the multiplication, that is associative, and a morphism , called the unit, that is both a left and right identity for .
For example, in the category of sets viewed as a monoidal category with respect to the cartesian product, monoids are precisely what we are used to call “monoids”: sets equipped with a binary associative operation together with a distinguished element that is both a left and right identity.
More interestingly, monoids in the category are precisely monads on the category !
If and are monoids in , then a monoid morphism from to is a morphism in that preserves multiplication and unit in the obvious sense. Monoids in thus form a category, which we denote by .
A suitable notion of morphism between monoidal categories is that of lax monoidal functor. If and are monoidal categories, then a lax monoidal functor from to consists of a functor together with a morphism and a natural transformation subject to certain coherence conditions. A lax monoidal functor is called strong or simply a monoidal functor if and are isomorphisms.
Lax monoidal functors have the following remarkable property: a lax monoidal functor gives rise to a functor . Namely, if is a monoid in , then becomes a monoid in if we define the multiplication by the composite and the unit by the composite . If is a monoid morphism, then so is , with respect to the multiplication and unit defined above.
Therefore, if we have a lax monoidal functor and a monoid in , we can conclude that is a monoid in the category , i.e., a monad.
Enough abstract nonsense. Here are two examples illustrating this observation.
The first is the writer monad. Let be a cartesian category. There is a functor from to the category that maps an object to the functor . This functor is clearly monoidal:
I omit the verification of the coherence conditions, which is straightforward. Therefore, if is a monoid in , then is a monad. The underlying functor of this monad coincides with the underlying functor of the writer monad. One can check that the monad structure obtained by translating the monoid structure on along the functor is the usual structure of the writer monad.
The second example is of the reader monad. Let be a cartesian closed category. There is a functor from the opposite of the category to that maps an object to the functor . The domain of is because is a contravariant functor. It is obviously monoidal, where the monoidal structure on is given by the cartesian product on (more generally, the opposite of a monoidal category is naturally a monoidal category):
Again, I omit the verification of the coherence conditions. If follows that if is a monoid in , then is a monad. However, every object of is naturally a monoid! Namely, the multiplication is a morphism in , i.e., a morphism in ; we take it to be the diagonal morphism. Similarly, the unit is a morphism in , i.e., a morphism in , and there is only one such morphism. It is straightforward to check that these morphisms turn into a monoid in . Hence is a monad. Again, a simple computation confirms that its structure, obtained by translating the monoid structure of along the functor , is the usual structure of the reader monad.
In both of these examples, the lax monoidal functor is actually strong. This need not be the case in general, and in a sequel to this post I hope to show an example of such a lax monoidal functor and monads its gives rise to.