Monad Actions

Previously, we have encountered various structures involving monads, such as Eilenberg-Moore algebras, Kleisli and Eilenberg-Moore laws, and distributive laws. In this post, we encounter another such structure, monad actions. These are less frequently discussed, but useful and relatively simple constructions. Conceptually, they sit somewhere between Eilenberg-Moore algebras and distributive laws.

Introducing actions

For a monad (\mathbb{M} : \mathcal{D} \rightarrow \mathcal{D}, \eta, \mu), a left action of \mathbb{M} on a functor A : \mathcal{C} \rightarrow \mathcal{D} is a natural transformation:

\alpha : M \circ A \Rightarrow A

such that the following two axioms hold:

  1. The unit axiom: \alpha \cdot (\eta \circ A) = \mathsf{id}_A
  2. The multiplication axiom: \alpha \cdot (\mu  \circ A) = \alpha \cdot (\mathbb{M} \circ \alpha)

Actions are also sometimes called modules in the literature, although there is some inconsistency in the use of this term, so we shall avoid it.

Remark: For those who have encountered them before, there is a close analogy between a left action of a monad on a functor, and the action of a monoid (or perhaps more commonly a group) on a set. In fact, at an appropriate level of abstraction, they are both instances of the same construction.

We begin with what is probably the motivating example.

Example: For any Eilenberg-Moore algebra

(A, a : \mathbb{M}(A) \rightarrow A)

we can consider the functor A : 1 \rightarrow \mathcal{D} from the terminal category, which picks out the object A. We use the same name for both the object and the corresponding functor, as both provide essentially the same data. From this perspective, a is a natural transformation a : \mathbb{M} \circ A \Rightarrow A. The axioms for an Eilenberg-Moore algebra exactly correspond to this natural transformation being a left monad action.

So Eilenberg-Moore algebras are a special case of left monad actions. There are of course more general examples:

Example: Let \mathbb{M}^+ be the non-empty multiset monad, and for n \geq 1 let \mathbb{M}^{\geq n} denote the functor forming collections of multisets of at least n elements. Taking unions of multisets induces a monad action:

\alpha : \mathbb{M}^+ \circ \mathbb{M}^{\geq n} \Rightarrow \mathbb{M}^{\geq n}.

Every set X induces an Eilenberg-Moore algebra:

\alpha_X : \mathbb{M}^+(\mathbb{M}^{\geq n}(X)) \rightarrow \mathbb{M}^{\geq n}(X)

Example: Let \mathbb{L} be the list monad, and E : \mathsf{Set} \rightarrow \mathsf{Set} be the functor mapping a set to the collection of even length lists of its elements. There is a left monad action:

\alpha : \mathbb{L} \circ E \rightarrow E

given by list concatenation. Again, every set X induces an Eilenberg-Moore algebra:

\alpha_X : \mathbb{L}(E(X)) \rightarrow E(X)

The previous two examples show that more general left actions can be seen as encoding a uniform family of Eilenberg-Moore algebras.

The notion of left monad action can be dualised. For an endofunctor

A : \mathcal{D} \rightarrow \mathcal{C}

a right monad action is a natural transformation:

\alpha : A \circ M \Rightarrow A

such that the following two axioms hold:

  1. The unit axiom: \alpha \cdot (A \circ \alpha) = \mathsf{id}_A
  2. The multiplication axiom: \alpha \cdot (A \circ \mu) = \alpha \cdot (\alpha \circ \mathbb{M})

We could go further and consider natural transformations where monads act on both the left and right, commonly referred to as bimodules. We could also dualise and consider both left and right (co)actions of comonads, although we shall resist the temptation to explore these related topics for now. For the rest of this post, we shall primarily focus on left actions of monads.

Building Monad Actions

So far, we have seen some reasonably ad-hoc looking examples of left monad actions. The only procedure we have for constructing monad actions is to view any Eilenberg-Moore algebra as a left action.

For a monad (\mathbb{M} : \mathbb{D} \rightarrow \mathbb{D}, \eta, \mu) as before, there are several more methods for systematically construction monad actions. For example:

  1. The monad multiplication \mu : \mathbb{M} \circ \mathbb{M} \Rightarrow \mathbb{M} is a left (and right) monad action.
  2. For A : \mathcal{C} \rightarrow \mathbb{D}, and H : \mathcal{B} \rightarrow \mathcal{C}, if \alpha : \mathbb{M} \circ A \Rightarrow A is a left monad action, then so is \alpha \circ H : \mathbb{M} \circ A \circ H \rightarrow A \circ H.
  3. If \alpha : M \circ A \rightarrow A is a monad action, a \tau : \mathbb{T} \Rightarrow \mathbb{M} a monad morphism, then \alpha \cdot (\tau \circ A) : \mathbb{T} \circ A \Rightarrow A is a left action of \mathbb{T}.

There are other methods, involving adjunctions and Kan extensions, but the constructions above are enough for our remaining discussions.

Monad Actions and Morphisms

Given any monad morphism

\tau : \mathbb{T} \Rightarrow \mathbb{M}

using two of the constructions in the previous section, we can build a monad action

\mu \cdot (\tau \circ \mathbb{M}) : \mathbb{T} \circ \mathbb{M} \Rightarrow \mathbb{M}

In fact, the resulting actions are special. They satisfy an extra compatibility axiom:

\mu \cdot (\alpha \circ \mathbb{M}) = \alpha \cdot (\mathbb{T} \circ \mu)

For any action

\alpha : \mathbb{T} \circ \mathbb{M} \Rightarrow \mathbb{M}

satisfying the compatibility axiom, the composite

\alpha \cdot (\mathbb{T} \circ \eta) : \mathbb{T} \Rightarrow \mathbb{M}

is a monad morphism. Furthermore, these two mapping exhibit a bijection between monad morphisms and monad actions satisfying the compatibility axiom. This handy relationship often allows us to move back and forth between the monad morphism and action perspectives as suites our needs.

Monad Actions and Laws

Given a left monad action \alpha : \mathbb{M} \circ A \Rightarrow A, and any other monad \mathbb{T} : \mathcal{C} \rightarrow \mathcal{C}, we can form the composite:

(A \circ \eta) \cdot \alpha : \mathbb{M} \circ A \Rightarrow  A \circ \mathbb{T}

It is not hard to verify that this is in fact an Eilenberg-Moore law. Forming the dual composite for a right action will yield a Kleisli law.

The point of these two simple constructions is that monad actions can be built and combined in various ways, and this now gives us a new route to building Eilenberg-Moore and Kleisli laws, which have many uses.

Conclusion

Although monad actions are perhaps a slightly more obscure aspect of monad theory than some of the topics we have covered, they are nonetheless useful. Verifying many of the claims above is straightforward, particularly if done using string diagrams, and monad actions interact well with string diagrammatic techniques. Monad actions will also prove handy tools in some future posts. From the point of view of computer science, they seem to be an under-investigated topic, ripe for further exploration.

Further reading: “Modules over Monads and their Algebras” by Piróg, Wu and Gibbons is an excellent computer science oriented source for background, and helped greatly with the examples in this post. The article prefers the term module rather than action, but hopefully this wont be too distracting in relating the ideas to our discussions. They also give nice examples of right actions, which we have paid less attention, interpreting them as computations in context.

2 thoughts on “Monad Actions”

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: