open import Cat.Bi.Base
open import Cat.Prelude

import Cat.Reasoning as Cr



Recall that a monad on a category $\ca{C}$ consists of a functor $M : \ca{C} \to \ca{C}$ and natural transformations $\mu : MM \To M$, $\eta : \id{Id} \To M$. While the words “functor” and “natural transformation” are specific to the setup where $\ca{C}$ is a category, if we replace those with “1-cell” and “2-cell”, then the definition works in any bicategory!

  record Monad (a : B.Ob) : Type (ℓ ⊔ ℓ′) where
field
M : a B.↦ a
μ : (M B.∘ M) B.⇒ M
η : B.id B.⇒ M


The setup is, in a sense, a lot more organic when phrased in an arbitrary bicategory: Rather than dealing with the specificities of natural transformations and the category $\ca{C}$, we abstract all of that away into the setup of the bicategory $\bf{B}$. All we need is that the multiplication $\mu$ be compatible with the associator $\alpha$, and the unit $\eta$ must be appropriately compatible with the left and right unitors $\lambda, \rho$.

      μ-assoc : μ B.⊗ (M B.▶ μ) ≡ μ B.⊗ (μ B.◀ M) B.⊗ B.α← M M M
μ-unitr : μ B.⊗ (M B.▶ η) ≡ B.ρ← M
μ-unitl : μ B.⊗ (η B.◀ M) ≡ B.λ← M


We can draw these compatibility conditions as pretty commputative diagrams. The commutative altar (on top) indicates associativity of multiplication, or more abstractly, compatibility of the multiplication with the associator. The commutative upside-down triangle indicates mutual compatibility of the multiplication and unit with the unitors.

## In Cat🔗

To prove that this is an actual generalisation of the 1-categorical notion, we push some symbols around and prove that a monad in the bicategory $\bf{Cat}$ is the same thing as a monad on some category. Things are set up so that this is almost definitional, but the compatibility paths have to be adjusted slightly. Check it out below:

module _ {o ℓ} {C : Precategory o ℓ} where
private module C = Cr C

ap (M.μ .η x C.∘_) (C.intror refl)
∙ ap (λ e → e .η x) M.μ-unitr
ap (M.μ .η x C.∘_) (C.introl (M.M .Functor.F-id))
∙ ap (λ e → e .η x) M.μ-unitl
ap (M.μ .η x C.∘_) (C.intror refl)
·· ap (λ e → e .η x) M.μ-assoc
·· ap (M.μ .η x C.∘_) (C.elimr refl ∙ C.eliml (M.M .Functor.F-id))