Monoid and Monad

Quora: What is the difference between monoid and monad? by Mort Yao

A well-said, perhaps the briefest ever answer is: monad is just a monoid in the category of endofunctors.

monoid is defined as an algebraic structure (generally, a set) M with a binary operation (multiplication) • : M × M → M and an identity element (unit) η : 1 → M, following two axioms:

i. Associativity
∀ a, b, c ∈ M, (a • b) • c = a • (b • c)

ii. Identity
∃ e ∈ M ∀ a ∈ M, e • a = a • e = a

When specifying an endofunctor T : X → X (which is a functor that maps a category to itself) as the set M, the Cartesian product of two sets is just the composition of two endofunctors; what you get from here is a monad, with these two natural transformations:

1. The binary operation is just a functor composition μ : T × T → T
2. The identity element is just an identity endofunctor η : I → T

Satisfied the monoid axioms (i. & ii.), a monad can be seen as a monoid which is an endofunctor together with two natural transformations. 

The name “monad” came from “monoid” and “triad”, which indicated that it is a triple (1 functor + 2 trasformations), monoidic algebraic structure.

In other words, monoid is a more general, abstract term. When applying it to the category of endofunctors, we have a monad.

State Monad: Milewski

BM 5&6 : Category Adjunctions 伴随函子

Adjunction is the “weakening of Equality” in Category Theory.

Equivalence of 2 Categories if:

5.2  Adjunction definition: (L, R, \epsilon, \eta ) such that the 2 triangle identities below ( red and blue) exist.

6.1 Prove: Let C any category, D a Set.

\boxed {\text {C(L 1, -)} \simeq \text {R}}

{\text {Right Adjoint R in Set category is }} {\text {ALWAYS Representable}}

1 = Singleton in Set D

From an element in the singleton Set always ‘picks’ (via the function) an image element from the other Set, hence :
\boxed {\text{Set (1, R c) } \simeq \text{Rc }}

Examples : Product & Exponential are Right Adjoints 

Note: Adjoint is a more powerful concept to understand than the universal construction of Product and Exponential.


\boxed  {\text {Every Adjunction gives a Monad}}


\boxed {\text {Left Adjoint: L } \dashv \text { R }}

R \circ \ L = m = \text { Monad}

L \circ \ C = \text { Co-Monad}

With Product (Left Adjoint) and Exponential (Right Adjoint) => \text {State Monad}

Category Theory II 2: Limits, Higher order functors

1.2 Introduction to Limit 

Analogy : Product to Cones (Limit)

2.1 Five categories used to define Limit:

  1. Index category (I)
  2. Category C: Functors (constant ,  D)
  3. Cones (Lim D)
  4. Functor Category [I, C ]:objects are (constant, D ), morphisms are natural transormations
  5. Set category of Hom-Set Cones [I,C] to Hom-Set C (c , Lim D )

2.2 Naturality

3.1 Examples: Equalizer

CoLimit = duality of Limit (inverted cone = co-Cone)

Functor Continuity = preserve Limit

BM Category Theory 10: Monad & Monoid

10.1 Monad

Function : compose “.“, Id

Monad: compose “>>=“, return

Imperative (with side effects eg. state, I/O, exception ) to Pure function by hiding or embellishment in Pure function but return “embellished” result.

10. 2 Monoid

Monoid in category of endo functors = Monad

Ref Book : 

What is the significance of monoids in category theory? by Bartosz Milewski 

Category Theory 9: Natural Transformations, BiCategories

In essence, in all kinds of Math, we do 3 things: 

1) Find Pattern among objects (numbers, shapes, …), 
2) Operate inside the objects (+ – × / …), 
3) Swap the object without modifying it (rotate, flip, move around, exchange…).

Category  consists of :
1) Find pattern thru Universal Construction in Objects (Set, Group, Ring, Vector Space, anything )
2) Functor which operates on 1).
3) Natural Transformation as in 3).

\boxed {\text {Natural Transformation}}

\boxed {\text {Morphism of Functors}}


Functors (F, G) := operation inside a container 
\boxed { F :: X \to F_{X}, \:  F :: Y \to F_{Y}}

\boxed {G :: X \to G_{X}, \: G :: Y \to G_{Y}}

Natural Transformation  ({\eta_{X}, \eta_{Y}}) := swap the content ( F_{X} \text { with } G_{X},  F_{Y} \text { with } G_{Y} ) in the container without modifying it.
\boxed{\eta_{X} :: F_{X} \to G_{X} , \: \eta_{Y} :: F_{Y} \to G_{Y}}

9.2 Bicategories 

“Diagram Chasing”:

2- Category

Cat = Category of categories (C, D)

The functors {F, G} instead of being a Set (“Hom-Set”) – like functions  form a function object “Exponentialfunctors also form a category, noted : \boxed {[C,D] = D^{C} }

BiCategory (different from 2-Category): the Associativity and Identity are not equal (as in 2-Category),  but only up to Isomorphism.
Note : when n is infinity,  n-Category & Groupoid (HOTT: Homotopy Type Theory)

Reading Book: chap 10