And again... A monad is a monoid in the category of endofunctors!
November 8, 2025
What do “normal” people do on weekends? Probably chores, relaxation, I don’t know in general!
Personally, on weekends I naturally spend most of my time with family and chores, and whatever time is left for my own stuff… well, for a long time now, and practically without deviation, I’ve been investing it all in “my own stuff.”
My stuff – that’s self-education, research, writing blog posts.
tl;dr Today I had a great rest! It seems I finally understood the meaning of the phrase “A monad is a monoid in the category of endofunctors.”
I had a vague, fragmented understanding before, but I couldn’t really explain what these words refer to specifically, or… at least roughly.
Through several iterations of conversation with Sonnet 4.5 (Reflection, agent search, and double-checking with LLMs - one of their best applications), I went from:
b-aa-aa, m-aa-aa. Wait, hold on, let’s figure this out separately and mercilessly, from the very basic principles in a spherical vacuum what a monad is, what a monoid is, let’s better remember morphisms/functors and endofunctors… brrr let’s go.
In the first sitting, I realized that we’re talking about, attention, the category of endofunctors, and here it wasn’t enough to understand what an endofunctor is, but even more importantly to understand basically what a category is at all.
In the middle of the second sitting, I understood what a monoid is. A monoid is generally the most understandable and simple thing here :)
Then I went to rewatch the excellent movie I, Robot (it turned out my wife hadn’t seen it, how could that be, I thought and in a completely legal way obtained a 2k version upscaled to pseudo 4k with the help of an LLM! I found this very amusing.)
In short, interrupting the viewing to put my son to sleep, I retreated to my cell and decided – let’s push it one last time
Here’s the unedited beginning of my last thinking letter on this topic:
okay let’s start from the very beginning now. I’ll try to write in my own words everything I “understood,” but essentially rather just memorized. So, a monad. A monad is… AHAHAHAHA A MONAD IS A MONOID IN THE CATEGORY OF ENDOFUNCTORS!!!! A monad itself is an algebraic structure ON AN ENDOFUNCTOR!!! And this endofunctor “WORKS” WITHIN ONE ORIGINAL CATEGORY. NOT the category of endofunctors!!!! A monad itself is a monoid because a monoid is also such an algebraic structure that has a set, a binary operation, and a unit element! In the case of a monad - the set is… a set of one endofunctor!?
And now let’s try to figure it out a bit, calm down and breathe out. Nothing is clear!:)
So we have some category.
What is a category?
A category is such an abstract structure that has objects and morphisms between them. The objects themselves have no properties at all - they are maximally abstract. All “properties” of objects are determined and expressed only by which morphisms enter and exit them.
In short, a category is objects + morphisms + composition of these morphisms + laws (category requirements).
A category also has a so-called “identity morphism,” which is essentially a neutral element, and… does nothing when composed with another morphism. This is important.
What is a functor?
A functor is a morphism between categories. Just as a regular function maps values from one set (domain) to another (codomain), a functor is also such a “mega-function,” only it doesn’t map primitive values, but entire structures (with properties and so on).
What is an endofunctor?
An endofunctor is such a functor that is closed in a category, the result of its “work” will be a type/object in the same category.
Here it should already be clear what the category of endofunctors is – when we talk about the category of endofunctors, we are already modeling morphisms between endofunctors. Roughly speaking, the category of endofunctors is a meta-category in relation to the category in which the elements of this category “work”/are closed.
Monoid
Now let’s understand what a monoid is. Probably - this is the simplest thing here.
A monoid is simply an algebraic structure that represents the following “set”:
- A set of values
- A binary operation (this is such an operation that from two elements of the set outputs some other element of the same set)
- and a neutral element that “does nothing”
Well, it seems everything is clear, only that very Monad remains.
What I started with – “A monad is an algebraic structure on an endofunctor” is not enough. The monad also “includes”:
Unit (Unit, η).
This is a natural transformation η: Id → T (from the identity functor to ours). This operation provides the embedding of a pure object A into its monadic form T(A). In code, this is called return or pure.
Multiplication (Multiplication, μ).
This is a natural transformation μ: T² → T, which collapses two levels of monadic structure into one. The composition T ∘ T → T is the basic foundation. The fact that it works for any number of levels Tⁿ → T is ensured by associativity and the “functoriality” of T itself.
But even this is not enough, because for the triple of endofunctor, unit, and multiplication to be considered a monad, it must satisfy three axioms of a MONOID (boo-boo-boo! here’s the surprise):
Associativity.
Associativity is easily understood through school mathematics:
(a × b) × c = a × (b × c)
For functors, this means that the result does not depend on the order of collapsing levels: collapsing the inner two layers and then the outer layer (μ ∘ Tμ) must be equal to collapsing the outer two layers and then the inner layer (μ ∘ μT).
Left unit and Right unit.
Remember the neutral element in a monoid? So for an element a from a monoidal set M, where e is the neutral element (unit), the left/right axioms are:
e · a = a a · e = a
At the monad level, the “neutral element” e is replaced by the operation η (wrapping), and the binary operation · is replaced by μ (collapsing).
The left unit requires that collapsing after wrapping (μ ∘ ηT) be the identity transformation. The right unit requires that wrapping from the inside and then collapsing (μ ∘ Tη) also be the identity transformation.
That’s it. A monad is an endofunctor T to which we have given the structure of a monoid (T, μ, η).
Why is all this needed, damn it!?
Well, firstly, in order to understand that
A monad is a monoid in the category of endofunctors
This is not a cryptic meme phrase but actually the definition of a monad. If you don’t memorize it, but at least a little, well, at least a little understand what it’s about and what monads express… Then you can understand why all this, damn it, is needed :)
Although categories, types, monads, and monoids are things from abstract algebra, and in programming they are generally present in explicit form in languages that are practically esoteric rather than applied… In implicit form, both monads and monoids, and categories with types can be found and modeled almost everywhere. Especially in software systems!
To the reasonable still question – “well, okay, but why is it needed?”
At least because the ability to see and understand monoids, categories, and types is, without jokes, brain firmware that allows you to model (and create according to these models) more reliable and powerful systems!