open import Cat.Functor.Adjoint
open import Cat.Functor.Base
open import Cat.Prelude

import Cat.Reasoning
module Cat.Diagram.Comonad where
open Functor
open _=>_

module _ {o β„“} {C : Precategory o β„“} where
  open Precategory C

ComonadsπŸ”—

A comonad on a category is dual to a monad on instead of a unit and multiplication we have a counit and comultiplication More generally, we can define what it means to equip a fixed functor with the structure of a comonad.

  record Comonad-on (W : Functor C C) : Type (o βŠ” β„“) where
    field
      counit : W => Id
      comult : W => (W F∘ W)
    module counit = _=>_ counit renaming (Ξ· to Ξ΅)
    module comult = _=>_ comult renaming (Ξ· to Ξ΄)

    open Functor W renaming (Fβ‚€ to Wβ‚€ ; F₁ to W₁ ; F-id to W-id ; F-∘ to W-∘) public
    open counit using (Ξ΅) public
    open comult using (Ξ΄) public

We also have equations governing the counit and comultiplication. Unsurprisingly, these are dual to the equations of a monad.

    field
      Ξ΄-idl   : βˆ€ {x} β†’ W₁ (Ξ΅ x) ∘ Ξ΄ x ≑ id
      Ξ΄-idr   : βˆ€ {x} β†’ Ξ΅ (Wβ‚€ x) ∘ Ξ΄ x ≑ id
      Ξ΄-assoc : βˆ€ {x} β†’ W₁ (Ξ΄ x) ∘ Ξ΄ x ≑ Ξ΄ (Wβ‚€ x) ∘ Ξ΄ x