Previously, we encountered two special types of distributive laws. Recall that, for a pair of monads , , and a functor :

- An Eilenberg-Moore law is a natural transformation of type , which appropriately preserves the monad structure. Eilenberg-Moore laws were in bijective correspondence with Eilenberg-Moore liftings of to a functor commuting with the forgetful functors from the Eilenberg-Moore category.
- A Kleisli-law is a natural transformation of type , which appropriately preserve the monad structure. These were in bijection with Kleisli liftings of to a functor , commuting with the free functors to the Kleisli category.

In this post, we are going to consider the special case of Kleisli and Eilenberg-Moore laws when is an endofunctor

and both monads and are equal, which we will refer to as

.

We shall see that in this special case, both Kleisli and Eilenberg-Moore laws have further applications, beyond their natural use lifting functors to Kleisli and Eilenberg-Moore categories.

## Connections to Endofunctor Algebras

As is now an endofunctor, we can consider the category of endofunctor algebras . Noting that our monad lives on the same category as , it is natural to ask if we can lift it to a monad on .

As a first step, we assume the existence of a natural transformation

If such a natural transformation exists, this induces an endofunctor

with action on objects

and on morphisms

So we can at least lift the endofunctor component to the category of algebras. We need to find components for the unit and multiplication of the lifted monad. The obvious choices are to take:

Of course, we must verify that these morphisms are actually -algebra homomorphisms. It turns out that this is the case if is a Kleisli law. It is also then straightforward to verify that these components form natural transformations, and satisfy the monad axioms, with the details following fairly directly from the same properties in the base category.

So we have shown that, given a Kleisli law

- There is an induced monad .
- The forgetful functor commutes with the monad structure, in that , and .

So, given a Kleisli law, the corresponding monad lifts in a very nice way to the category of endofunctor algebras.

**Example**: Given a commutative monad , the canonical natural transformation

is a Kleisli law. For example, for the powerset monad is commutative with:

Given an algebra , the action of the structure map of is:

That is, the algebra operation is applied pointwise on every possible combination of the inputs. A similar strategy can be used to lift any commutative monad to the category of algebras for any polynomial functor.

## Connections to Endofunctor Coalgebras

As we have assumed is an endofunctor, it is equally natural to consider the category of endofunctor coalgebras . Again, we should ask ourselves if it is possible to lift the monad to the category of coalgebras. As before, as first step it is convenient to assume the existence of a natural transformation of an appropriate type, this time:

With this in place, we can define a functor:

with action on objects:

and on morphisms:

So the existence of any of the right type allows us to lift endofunctor component of the monad. As in the case of algebras, the obvious choice for the components of the unit and multiplication is to define:

As before, we must confirm that these components are legitimate -morphisms. This turns out to be the case when satisfies the axioms of an Eilenberg-Moore law. As before, verifying naturality and the monad axioms can be reduced to the same properties in the base category.

So we have shown that, given an Eilenberg-Moore law

- There is an induced monad .
- The forgetful functor commutes with the monad structure, in that , and .

So Eilenberg-Moore laws induce well-behaved monads on categories of coalgebras.

**Example**: For a fixed set , we consider the endofunctor

A coalgebra of this functor is essentially a function of type:

From a computer science perspective, we can think of this as modelling a deterministic process with state space , and after each computation step outputs an element of , and continues in a new state. Given an Eilenberg-Moore algebra of the powerset monad , there is an Eilenberg-Moore law:

such that

So the structure maps of the coalgebra will evaluate a set of states pointwise, using the provided Eilenberg-Moore algebra to calculate a suitable output value from the set of available candidates.

## Conclusion

It is interesting that these special cases of Kleisli and Eilenberg-Moore laws allow us to perform further constructions. The fact that Kleisli laws induce monads on categories of algebras is probably not that shocking, but that Eilenberg-Moore laws have something to do with monads on categories of *coalgebras* is a bit more of a surprise. Probably the main takeaway is that, yet again, the ability to suitably commute monad structure with a natural transformation arises in many situations and is an important idea.

Attendees at the recent Midlands Graduate School who attended my string diagrams course may recognise some of the ideas in this post, as the constructions and calculations are in my opinion significantly easier to grasp graphically.

**Further reading**: I am not aware of a source for the observations above, although I assume it is folklore / well-known if you hang out at the right sort of parties. I would be interested in knowing if there is a published source to cite. Bart Jacobs wonderful book “Introduction to Coalgebra” has inductive constructions for Kleisli and Eilenberg-Moore laws, which would be useful in playing with the ideas discussed in this post.

**Acknowledgments**: Thanks to Sjoerd Visscher for spotting a distracting typo in an earlier version.