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

import Cat.Reasoning as Cr

module Cat.Bi.Diagram.Monad  where

open _=>_

module _ {o ℓ ℓ'} (B : Prebicategory o ℓ ℓ') where
private module B = Prebicategory B


Recall that a monad on a category $\mathcal{C}$ consists of a functor $M : \mathcal{C} \to \mathcal{C}$ and natural transformations $\mu : MM \Rightarrow M$, $\eta : \operatorname{id}_{} \Rightarrow M$. While the words “functor” and “natural transformation” are specific to the setup where $\mathcal{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 $\mathcal{C}$, we abstract all of that away into the setup of the bicategory $\mathbf{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 $\mathbf{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)
∙ M.μ-unitr ηₚ x
ap (M.μ .η x C.∘_) (C.introl (M.M .Functor.F-id))
∙ M.μ-unitl ηₚ x
ap (M.μ .η x C.∘_) (C.intror refl)
·· M.μ-assoc ηₚ x
·· ap (M.μ .η x C.∘_) (C.elimr refl ∙ C.eliml (M.M .Functor.F-id))