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

import Cat.Diagram.Monad as Cat
import Cat.Reasoning as Cr

module Cat.Bi.Diagram.Monad  where

Monads in a bicategoryπŸ”—

Recall that a monad on a category C\ca{C} consists of a functor M:Cβ†’CM : \ca{C} \to \ca{C} and natural transformations ΞΌ:MMβ‡’M\mu : MM \To M, Ξ·:Idβ‡’M\eta : \id{Id} \To M. While the words β€œfunctor” and β€œnatural transformation” are specific to the setup where C\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
      M : a B.↦ a
      ΞΌ : (M B.∘ M) B.β‡’ M
      Ξ· : 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 C\ca{C}, we abstract all of that away into the setup of the bicategory B\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 Cat\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
  open Cat.Monad
  open Monad
  private module C = Cr C

  Bicat-monad→monad : Monad (Cat _ _) C → Cat.Monad C
  Bicat-monad→monad monad = monad′ where
    private module M = Monad monad

    monadβ€² : Cat.Monad C
    monadβ€² .M = M.M
    monadβ€² .unit = M.Ξ·
    monadβ€² .mult = M.ΞΌ
    monadβ€² .left-ident {x} =
        ap (M.μ .η x C.∘_) (C.intror refl)
      βˆ™ ap (Ξ» e β†’ e .Ξ· x) M.ΞΌ-unitr
    monadβ€² .right-ident {x} =
        ap (M.μ .η x C.∘_) (C.introl (M.M .Functor.F-id))
      βˆ™ ap (Ξ» e β†’ e .Ξ· x) M.ΞΌ-unitl
    monadβ€² .mult-assoc {x} =
        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))

  Monad→bicat-monad : Cat.Monad C → Monad (Cat _ _) C
  Monad→bicat-monad monad = monad′ where
    private module M = Cat.Monad monad

    monadβ€² : Monad (Cat _ _) C
    monadβ€² .M = M.M
    monadβ€² .ΞΌ = M.mult
    monadβ€² .Ξ· = M.unit
    monadβ€² .ΞΌ-assoc = Nat-path Ξ» _ β†’
        ap (M.mult .η _ C.∘_) (C.elimr refl)
     Β·Β· M.mult-assoc
     Β·Β· ap (M.mult .Ξ· _ C.∘_) (C.introl (M.M .Functor.F-id) βˆ™ C.intror refl)
    monadβ€² .ΞΌ-unitr = Nat-path Ξ» _ β†’
        ap (M.mult .η _ C.∘_) (C.elimr refl)
      βˆ™ M.left-ident
    monadβ€² .ΞΌ-unitl = Nat-path Ξ» _ β†’
        ap (M.mult .η _ C.∘_) (C.eliml (M.M .Functor.F-id))
      βˆ™ M.right-ident