|
| 1 | +{-# OPTIONS --safe --without-K #-} |
| 2 | + |
| 3 | +open import Categories.Category.Core using (Category) |
| 4 | +open import Categories.Functor using (Endofunctor; Functor) |
| 5 | + |
| 6 | +module Categories.Comonad.Distributive {o ℓ e} (C : Category o ℓ e) (F : Endofunctor C) where |
| 7 | + |
| 8 | +open import Categories.Category.Construction.F-Algebras using (F-Algebras) |
| 9 | +open import Categories.Comonad using (Comonad) renaming (id to idW) |
| 10 | +open import Categories.Functor.Algebra using (F-Algebra; F-Algebra-Morphism) |
| 11 | +open import Categories.Functor.DistributiveLaw using (DistributiveLaw) |
| 12 | +open import Categories.Functor.Properties using ([_]-resp-square) |
| 13 | +open import Categories.Morphism.Reasoning C |
| 14 | +open import Categories.NaturalTransformation using (NaturalTransformation) |
| 15 | + |
| 16 | +open import Level using (_⊔_) |
| 17 | + |
| 18 | +private |
| 19 | + module C = Category C |
| 20 | + module F = Functor F |
| 21 | + |
| 22 | +open C using (_∘_; _≈_) |
| 23 | +open C.HomReasoning |
| 24 | + |
| 25 | +record DistributiveComonad : Set (o ⊔ ℓ ⊔ e) where |
| 26 | + field |
| 27 | + comonad : Comonad C |
| 28 | + open Comonad comonad public renaming (F to N; module F to N) |
| 29 | + field |
| 30 | + distrib : DistributiveLaw F N |
| 31 | + module distrib = NaturalTransformation distrib |
| 32 | + |
| 33 | + field |
| 34 | + ε-distrib : ∀ {A} → ε.η (F.₀ A) ∘ distrib.η A ≈ F.₁ (ε.η A) |
| 35 | + δ-distrib : ∀ {A} → δ.η (F.₀ A) ∘ distrib.η A ≈ N.₁ (distrib.η A) ∘ distrib.η (N.₀ A) ∘ F.₁ (δ.η A) |
| 36 | + |
| 37 | + -- An F-distributive comonad lifts to a comonad on F-algebras |
| 38 | + lifted : Comonad (F-Algebras F) |
| 39 | + lifted = record |
| 40 | + { F = record |
| 41 | + { F₀ = λ X → record |
| 42 | + { A = N.₀ (F-Algebra.A X) |
| 43 | + ; α = N.₁ (F-Algebra.α X) ∘ distrib.η _ |
| 44 | + } |
| 45 | + ; F₁ = λ f → record |
| 46 | + { f = N.₁ (F-Algebra-Morphism.f f) |
| 47 | + ; commutes = glue′ |
| 48 | + ([ N ]-resp-square (F-Algebra-Morphism.commutes f)) |
| 49 | + (distrib.sym-commute (F-Algebra-Morphism.f f)) |
| 50 | + } |
| 51 | + ; identity = N.identity |
| 52 | + ; homomorphism = N.homomorphism |
| 53 | + ; F-resp-≈ = N.F-resp-≈ |
| 54 | + } |
| 55 | + ; ε = record |
| 56 | + { η = λ X → record |
| 57 | + { f = ε.η _ |
| 58 | + ; commutes = glue◽◃ (ε.commute _) ε-distrib |
| 59 | + } |
| 60 | + ; commute = λ f → ε.commute _ |
| 61 | + ; sym-commute = λ f → ε.sym-commute _ |
| 62 | + } |
| 63 | + ; δ = record |
| 64 | + { η = λ X → record |
| 65 | + { f = δ.η _ |
| 66 | + ; commutes = begin |
| 67 | + δ.η _ ∘ (N.₁ _ ∘ distrib.η _) ≈⟨ pullˡ (δ.commute _) ⟩ |
| 68 | + (N.₁ (N.₁ _) ∘ δ.η _) ∘ distrib.η _ ≈⟨ pullʳ δ-distrib ⟩ |
| 69 | + N.₁ (N.₁ _) ∘ (N.₁ (distrib.η _) ∘ (distrib.η _ ∘ F.₁ (δ.η _))) ≈⟨ pullˡ (C.Equiv.sym N.homomorphism) ⟩ |
| 70 | + N.₁ (N.₁ _ ∘ distrib.η _) ∘ (distrib.η _ ∘ F.₁ (δ.η _)) ≈⟨ C.sym-assoc ⟩ |
| 71 | + (N.₁ (N.₁ _ ∘ distrib.η _) ∘ distrib.η _) ∘ F.₁ (δ.η _) ∎ |
| 72 | + } |
| 73 | + ; commute = λ f → δ.commute _ |
| 74 | + ; sym-commute = λ f → δ.sym-commute _ |
| 75 | + } |
| 76 | + ; assoc = assoc |
| 77 | + ; sym-assoc = sym-assoc |
| 78 | + ; identityˡ = identityˡ |
| 79 | + ; identityʳ = identityʳ |
| 80 | + } |
| 81 | + |
| 82 | +-- The identity comonad distributes over any endofunctor |
| 83 | +id : DistributiveComonad |
| 84 | +id = record |
| 85 | + { comonad = idW C |
| 86 | + ; distrib = record |
| 87 | + { η = λ X → C.id |
| 88 | + ; commute = λ _ → id-comm-sym |
| 89 | + ; sym-commute = λ _ → id-comm |
| 90 | + } |
| 91 | + ; ε-distrib = begin |
| 92 | + C.id C.∘ C.id ≈⟨ C.identity² ⟩ |
| 93 | + C.id ≈⟨ F.identity ⟨ |
| 94 | + F.₁ C.id ∎ |
| 95 | + ; δ-distrib = C.∘-resp-≈ʳ (introʳ F.identity) |
| 96 | + } |
0 commit comments