module Cat.Instances.Monads where
Categories of monads🔗
The category of monads of a category consists of monads on and natural transformations preserving the monadic structure. In terms of the bicategory of monads in , a morphism in the 1-categorical version always has the identity functor as the underlying 1-cell. That is, this 1-category of monads on is the fibre of the displayed bicategory of monads in over
A monad homomorphism is a natural transformation preserving the unit and the multiplication In other words, the following two diagrams commute, where is the horizontal composition:
record Monad-hom (M N : Monad C) : Type (o ⊔ h) where
no-eta-equality
module M = Monad M
module N = Monad N
field
: M.M => N.M
nat open _=>_ nat public
field
: nat ∘nt M.unit ≡ N.unit
pres-unit : nat ∘nt M.mult ≡ N.mult ∘nt (nat ◆ nat) pres-mult
We have the identity and composition as expected.
: ∀ {M : Monad C} → Monad-hom M M
monad-hom-id {M = _} .Monad-hom.nat = idnt
monad-hom-id {M = _} .Monad-hom.pres-unit = Endo.idl _
monad-hom-id {M = M} .Monad-hom.pres-mult =
monad-hom-id let module M = Monad M in
.mult ≡⟨ Endo.id-comm-sym ⟩
idnt ∘nt M.mult ∘nt idnt ≡˘⟨ ap (M.mult ∘nt_) Endo-∘.F-id ⟩
M.mult ∘nt (idnt ◆ idnt) ∎
M
monad-hom-∘: ∀ {M N O : Monad C}
→ Monad-hom N O
→ Monad-hom M N
→ Monad-hom M O
{M = M} {N} {O} ν ξ = mh where
monad-hom-∘ module M = Monad M
module N = Monad N
module O = Monad O
module ν = Monad-hom ν
module ξ = Monad-hom ξ
: Monad-hom M O
mh .Monad-hom.nat = ν.nat ∘nt ξ.nat
mh .Monad-hom.pres-unit =
mh (ν.nat ∘nt ξ.nat) ∘nt M.unit ≡˘⟨ Endo.assoc ν.nat ξ.nat M.unit ⟩
.nat ∘nt (ξ.nat ∘nt M.unit) ≡⟨ ap (ν.nat ∘nt_) ξ.pres-unit ⟩
ν.nat ∘nt N.unit ≡⟨ ν.pres-unit ⟩
ν.unit ∎
O.Monad-hom.pres-mult =
mh (ν.nat ∘nt ξ.nat) ∘nt M.mult ≡˘⟨ Endo.assoc ν.nat ξ.nat M.mult ⟩
.nat ∘nt (ξ.nat ∘nt M.mult) ≡⟨ ap (ν.nat ∘nt_) ξ.pres-mult ⟩
ν.nat ∘nt (N.mult ∘nt (ξ.nat ◆ ξ.nat)) ≡⟨ Endo.assoc ν.nat N.mult (ξ.nat ◆ ξ.nat) ⟩
ν(ν.nat ∘nt N.mult) ∘nt (ξ.nat ◆ ξ.nat) ≡⟨ ap (_∘nt (ξ.nat ◆ ξ.nat)) ν.pres-mult ⟩
(O.mult ∘nt (ν.nat ◆ ν.nat)) ∘nt (ξ.nat ◆ ξ.nat) ≡˘⟨ Endo.assoc O.mult (ν.nat ◆ ν.nat) (ξ.nat ◆ ξ.nat) ⟩
.mult ∘nt ((ν.nat ◆ ν.nat) ∘nt (ξ.nat ◆ ξ.nat)) ≡˘⟨ ap (O.mult ∘nt_) $ Endo-∘.F-∘ (ν.nat , ν.nat) (ξ.nat , ξ.nat) ⟩
O.mult ∘nt ((ν.nat ∘nt ξ.nat) ◆ (ν.nat ∘nt ξ.nat)) ∎ O
Putting these together, we have the category of monads.
: ∀ (C : Precategory o h) → Precategory (o ⊔ h) (o ⊔ h)
Monads .Ob = Monad C
Monads C .Hom = Monad-hom
Monads C .Hom-set _ _ = hlevel 2
Monads C .id = monad-hom-id
Monads C ._∘_ = monad-hom-∘
Monads C .idr _ = ext λ _ → C .idr _
Monads C .idl _ = ext λ _ → C .idl _
Monads C .assoc _ _ _ = ext λ _ → C .assoc _ _ _ Monads C