module Cat.Monoidal.Diagram.Monoid.Duality {o ℓ}
  {C : Precategory o ℓ} (Cᵐ : Monoidal-category C)
  where

Duality of monoids and comonoids🔗

The duality of monoids and comonoids in a monoidal category is manifested by an isomorphism of displayed precategories

Our first step is to show that for any the structure of a Monoid-object-on in is the same as the structure of a Comonoid-object-on in the category

module On {x : C.Ob} where
  Monᵒᵖ→Comon : Monoid-on (Cᵐ ^mop) x → Comonoid-on Cᵐ x
  Monᵒᵖ→Comon xᵐ = record where
    ε = xᵐ .η
    Δ = xᵐ .μ
    Δ-counitl = xᵐ .μ-unitl
    Δ-counitr = xᵐ .μ-unitr
    Δ-coassoc = xᵐ .μ-assoc ∙ sym (C.assoc _ _ _)

  Comon→Monᵒᵖ : Comonoid-on Cᵐ x → Monoid-on (Cᵐ ^mop) x
  Comon→Monᵒᵖ xᶜ = record where
    η = xᶜ .ε
    μ = xᶜ .Δ
    μ-unitl = xᶜ .Δ-counitl
    μ-unitr = xᶜ .Δ-counitr
    μ-assoc = xᶜ .Δ-coassoc ∙ C.assoc _ _ _

  Monᵒᵖ≅Comon : Iso (Monoid-on (Cᵐ ^mop) x) (Comonoid-on Cᵐ x)
  Monᵒᵖ≅Comon = Monᵒᵖ→Comon , iso Comon→Monᵒᵖ rinv linv where
    rinv : is-right-inverse Comon→Monᵒᵖ Monᵒᵖ→Comon
    rinv xᶜ = Comonoid-on-path refl refl

    linv : is-left-inverse Comon→Monᵒᵖ Monᵒᵖ→Comon
    linv xᵐ = Monoid-on-path refl refl

  Monᵒᵖ≃Comon : Monoid-on (Cᵐ ^mop) x ≃ Comonoid-on Cᵐ x
  Monᵒᵖ≃Comon = Iso→Equiv Monᵒᵖ≅Comon

Next we extend this correspondence to morphisms, giving a displayed functor Monᵒᵖ→Comon between Monᵒᵖ and Comon over the isomorphism of precategories ^op^op→:

Comon : Displayed C ℓ ℓ
Comon = Comon[ Cᵐ ]
Monᵒᵖ : Displayed (C ^op ^op) ℓ ℓ
Monᵒᵖ = Mon[ Cᵐ ^mop ] ^total-op

Monᵒᵖ→Comon : Displayed-functor ^op^op→ Monᵒᵖ Comon
Monᵒᵖ→Comon = record where
  F₀' = On.Monᵒᵖ→Comon
  F₁' fᵐ = record
    { pres-ε = fᵐ .is-monoid-hom.pres-η
    ; pres-Δ = fᵐ .is-monoid-hom.pres-μ ∙ (C.-⊗-.rlmap _ _ C.⟩∘⟨refl) }
  F-id' = prop!
  F-∘' = prop!

Finally we show that Monᵒᵖ→Comon is an isomorphism of displayed precategories.

open is-precat-iso[_]
Monᵒᵖ→Comon-is-iso[] : is-precat-iso[ ^op^op-is-iso ] Monᵒᵖ→Comon
Monᵒᵖ→Comon-is-iso[] .has-is-iso' x = On.Monᵒᵖ≃Comon .snd
Monᵒᵖ→Comon-is-iso[] .has-is-ff' = biimp-is-equiv! (Monᵒᵖ→Comon.₁') λ fᶜ → record
  { pres-η = fᶜ .is-comonoid-hom.pres-ε
  ; pres-μ = fᶜ .is-comonoid-hom.pres-Δ ∙ (C.-⊗-.lrmap _ _ C.⟩∘⟨refl)
  }

Thus we also have a total isomorphism of precategories between the corresponding total categories.