I am trying to understand better how the category definition of monad is related to the computer science definition. nlab has a rather terse definition of Monad in terms of a bicategory.
- an object $a$
- an endomorphism $t: a \to a$
- $2$-cells $\mu, \eta$ (multiplication and unit).
For the case of programming languages, what are the objects (0-cells), morphisms (1-cells) and 2-morphisms (2-cells)? I am guessing the object is a type and multiplication is the >>=
operator (some way of putting commands in succession). I won' t know what the endomorphism $t$ could be.
I was told that list
is a monad, so is maybe
and IO
but I don't see the category or endomorphisms there.
Alternatively they have another definition that kind of makes sense:
Indeed, one can define a monad on an object a of a bicategory K as just a monoid in the endomorphism category K(a,a).
Are the endomorphism the lines of code preserving the type a?
nLab goes on to say, that monads can be represented as string diagrams. Here are
The axioms for a monad - could be represented in terms of the >>=
operator in a language like Haskell - are represented in terms of string diagrams.
Then, can a computer program be represented in terms of these diagrams?
This is a sequel to a previous question: https://cs.stackexchange.com/questions/30757/how-is-io-a-monad and can be migrated at the discretion of the admins.