Comonads¶
Comonad definitions with counits, comultiplications, and comonad laws.
comonads
¶
Comonads and coKleisli categories on V-enriched FinSet.
A comonad (W, ε, δ) consists of an endofunctor W, a counit ε: W ⇒ Id, and a comultiplication δ: W ⇒ W² satisfying:
W(δ) ∘ δ = δ_W ∘ δ (coassociativity)
ε_W ∘ δ = id (left counit)
W(ε) ∘ δ = id (right counit)
The coKleisli category of a comonad has the same objects but morphisms A → B are morphisms W(A) → B in the base category, composed via:
f =>> g = g ∘ W(f) ∘ δ_A
This module provides:
Comonad (abstract)
├── CofreeComonad — cofree comonad from a functor
└── DiagonalComonad — W(A) = A × A with diagonal/projection
CoKleisliCategory — wraps a comonad for composition
Comonad
¶
Bases: ABC
Abstract comonad (W, ε, δ) on V-enriched FinSet.
Subclasses must implement endofunctor, counit, and comultiply. CoKleisli composition is derived.
counit
abstractmethod
¶
comultiply
abstractmethod
¶
cokleisli_compose
¶
CoKleisli composition: f =>> g = g ∘ W(f) ∘ δ_A.
For f: W(A) → B and g: W(B) → C, produces W(A) → C.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
Left coKleisli morphism W(A) → B.
TYPE:
|
g
|
Right coKleisli morphism W(B) → C.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Morphism
|
Composed coKleisli morphism W(A) → C. |
Source code in src/quivers/monadic/comonads.py
CoKleisliCategory
¶
CoKleisliCategory(comonad: Comonad)
The coKleisli category of a comonad.
Objects are the same as the base category. Morphisms A → B in the coKleisli category are morphisms W(A) → B in the base category.
| PARAMETER | DESCRIPTION |
|---|---|
comonad
|
The underlying comonad.
TYPE:
|
Source code in src/quivers/monadic/comonads.py
identity
¶
DiagonalComonad
¶
DiagonalComonad(algebra: Algebra | None = None)
Bases: Comonad
The diagonal comonad W(A) = A × A with projection and diagonal.
ε_A: A × A → A is the first projection. δ_A: A × A → (A × A) × (A × A) is the diagonal on pairs.
This comonad models "contexts" where each element has access to a pair of values. It arises from the product adjunction Δ ⊣ ×.
| PARAMETER | DESCRIPTION |
|---|---|
algebra
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
Source code in src/quivers/monadic/comonads.py
counit
¶
ε_A: A × A → A is first projection.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The object A.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObservedMorphism
|
The projection morphism. |
Source code in src/quivers/monadic/comonads.py
comultiply
¶
δ_A: A × A → (A × A) × (A × A) is diagonal on pairs.
Maps (a1, a2) to ((a1, a2), (a1, a2)).
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The object A.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObservedMorphism
|
The comultiplication morphism. |
Source code in src/quivers/monadic/comonads.py
cokleisli_compose
¶
CoKleisli composition using the diagonal comonad.
Source code in src/quivers/monadic/comonads.py
CofreeComonad
¶
Bases: Comonad
The cofree comonad W(A) = A × S for a fixed store object S.
Also known as the "store comonad" or "costate comonad" on finite sets.
ε_A: A × S → A is the first projection (extract the value). δ_A: A × S → (A × S) × S duplicates the store component.
| PARAMETER | DESCRIPTION |
|---|---|
store
|
The fixed store/environment object S.
TYPE:
|
algebra
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
Source code in src/quivers/monadic/comonads.py
counit
¶
ε_A: A × S → A is the first projection.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The object A.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObservedMorphism
|
The extraction morphism. |
Source code in src/quivers/monadic/comonads.py
comultiply
¶
δ_A: A × S → (A × S) × S duplicates the store.
Maps (a, s) to ((a, s), s).
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The object A.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObservedMorphism
|
The comultiplication morphism. |