Recently I started looking into the origin of computer science monad, and found out that at least some of them originate in pretty simple things. Like segments of simplicial category Δ (for a better explanation/definition, see MacLane, p.175). Here I'll give a couple of examples, Option and Reader monads, how they derive from a very simple subcategory of Δ.
0, 1, 1+1
I'm going to introduce a very simple category, consisting of three, well, sets: empty, singleton and a union of two singletons (1+1), together with two arrows,
0 → 1and
1+1 → 1:
There's not much to talk about this category; you can think of it as living in the category of all sets, but actually any category with finite limits and colimits contains it.
Now I'll show how it generates two popular monads.
Given an object
X, if we add
Xto each part of the diagram
(a), we get this:
which is exactly Option Monad.
First, we multiply the diagram
Then we can do the same trick as in Option Monad, add an
This is Exception Monad.
X, we can build the following diagram by applying
X-functor to the diagram
Which is, simply speaking, just
Now this can be used to build the following diagram, for any
Do you see Reader diagram? It is the functor , with all the natural properties that follow from the naturality of the morphisms above.
This post is work in progress; comments are very welcome.