open import Cat.Diagram.Comonad
open import Cat.Functor.Adjoint
open import Cat.Prelude

open Comonad-on
open Functor
open _=>_

The comonad from an adjunction🔗

module
  Cat.Functor.Adjoint.Comonad
  {o₁ h₁ o₂ h₂ : _}
  {C : Precategory o₁ h₁}
  {D : Precategory o₂ h₂}
  {L : Functor C D} {R : Functor D C}
  (L⊣R : L ⊣ R)
  where
private
  module C = Precategory C
  module D = Precategory D
  module L = Functor L
  module R = Functor R
  module adj = __ L⊣R

Every adjunction gives rise to a comonad, where the underlying functor is This is dual to the construction of the monad from an adjunction.

Adjunction→Comonad : Comonad-on (L F∘ R)

The counit of the comonad is just the adjunction counit, and the comultiplication comes from the unit.

Adjunction→Comonad .counit = adj.counit
Adjunction→Comonad .comult = NT  x  L.(adj.η (R.₀ x))) λ x y f 
  L.(adj.η (R.₀ y)) D.∘ L.(R.₁ f)             ≡˘⟨ L.F-∘ _ _
  L.(adj.η (R.₀ y) C.∘ R.₁ f)                   ≡⟨ ap L.(adj.unit.is-natural _ _ _)
  L.(R.(L.(R.₁ f)) C.∘ adj.η (R.₀ x))       ≡⟨ L.F-∘ _ _
  L.(R.(L.(R.₁ f))) D.∘ L.(adj.η (R.₀ x))

The comonad laws follow from the zig-zag identities. In fact, the right identity law is exactly the zig identity.

Adjunction→Comonad .δ-unitr {x} = adj.zig

The others are slightly more involved.

Adjunction→Comonad .δ-unitl {x} = path where abstract
  path : L.(R.(adj.ε x)) D.∘ L.(adj.η (R.F₀ x)) ≡ D.id
  path =
    L.(R.(adj.ε _)) D.∘ L.(adj.η _) ≡⟨ sym (L.F-∘ _ _)
    L.(R.(adj.ε _) C.∘ adj.η _)       ≡⟨ ap L.₁ adj.zag ⟩
    L.₁ C.id                              ≡⟨ L.F-id ⟩
    D.id                                  ∎

Adjunction→Comonad .δ-assoc {x} = path where abstract
  path : L.(R.(L.(adj.η (R.F₀ x)))) D.∘ L.(adj.η _)
       ≡ L.(adj.η (R .F₀ (L.F₀ (R.F₀ x)))) D.∘ L.(adj.η _)
  path =
    L.(R.(L.(adj.η _))) D.∘ L.(adj.η _)   ≡⟨ sym (L.F-∘ _ _)
    L.(R.(L.(adj.η _)) C.∘ adj.η _)         ≡˘⟨ ap L.(adj.unit.is-natural _ _ _)
    L.(adj.η _ C.∘ adj.η _)                     ≡⟨ L.F-∘ _ _
    L.(adj.η _) D.∘ L.(adj.η _)