| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Propertiers of any for containers |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Container.Morphism.Properties where |
| 10 |
|
| 11 |
open import Level using (_⊔_; suc) |
| 12 |
open import Function.Base as F using (_$_) |
| 13 |
open import Data.Product.Base using (∃; proj₁; proj₂; _,_) |
| 14 |
open import Relation.Binary.Bundles using (Setoid) |
| 15 |
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_; _≗_) |
| 16 |
open import Data.Container.Core using (Container; _⇒_; ⟦_⟧; position; shape; map; ⟪_⟫) |
| 17 |
open import Data.Container.Morphism using (id; _∘_) |
| 18 |
open import Data.Container.Relation.Binary.Equality.Setoid using (refl; Eq) |
| 19 |
-- Identity |
| 20 |
|
| 21 |
module _ {s p} (C : Container s p) where |
| 22 |
|
| 23 |
id-correct : ∀ {x} {X : Set x} → ⟪ id C ⟫ {X = X} ≗ F.id |
| 24 |
id-correct x = ≡.refl |
| 25 |
|
| 26 |
-- Composition. |
| 27 |
|
| 28 |
module _ {s₁ s₂ s₃ p₁ p₂ p₃} |
| 29 |
{C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂} {C₃ : Container s₃ p₃} |
| 30 |
where |
| 31 |
|
| 32 |
∘-correct : (f : C₂ ⇒ C₃) (g : C₁ ⇒ C₂) → ∀ {x} {X : Set x} → |
| 33 |
⟪ f ∘ g ⟫ {X = X} ≗ (⟪ f ⟫ F.∘ ⟪ g ⟫) |
| 34 |
∘-correct f g xs = ≡.refl |
| 35 |
|
| 36 |
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂} where |
| 37 |
|
| 38 |
-- Naturality. |
| 39 |
|
| 40 |
Natural : ∀ x e → (∀ {X : Set x} → ⟦ C₁ ⟧ X → ⟦ C₂ ⟧ X) → |
| 41 |
Set (s₁ ⊔ s₂ ⊔ p₁ ⊔ p₂ ⊔ suc (x ⊔ e)) |
| 42 |
Natural x e m = |
| 43 |
∀ {X : Set x} (Y : Setoid x e) → let module Y = Setoid Y in |
| 44 |
(f : X → Y.Carrier) (xs : ⟦ C₁ ⟧ X) → |
| 45 |
Eq Y C₂ (m $ map f xs) (map f $ m xs) |
| 46 |
|
| 47 |
-- Container morphisms are natural. |
| 48 |
|
| 49 |
natural : ∀ (m : C₁ ⇒ C₂) x e → Natural x e ⟪ m ⟫ |
| 50 |
natural m x e Y f xs = refl Y C₂ |
| 51 |
|
| 52 |
module _ {s₁ s₂ p₁ p₂} (C₁ : Container s₁ p₁) (C₂ : Container s₂ p₂) where |
| 53 |
|
| 54 |
-- Natural transformations. |
| 55 |
|
| 56 |
NT : ∀ x e → Set (s₁ ⊔ s₂ ⊔ p₁ ⊔ p₂ ⊔ suc (x ⊔ e)) |
| 57 |
NT x e = ∃ λ (m : ∀ {X : Set x} → ⟦ C₁ ⟧ X → ⟦ C₂ ⟧ X) → Natural x e m |
| 58 |
|
| 59 |
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂} where |
| 60 |
|
| 61 |
-- All natural functions of the right type are container morphisms. |
| 62 |
|
| 63 |
complete : ∀ {e} → (nt : NT C₁ C₂ p₁ e) → |
| 64 |
∃ λ m → (X : Setoid p₁ e) → let module X = Setoid X in |
| 65 |
∀ xs → Eq X C₂ (proj₁ nt xs) (⟪ m ⟫ xs) |
| 66 |
complete (nt , nat) = |
| 67 |
(m , λ X xs → nat X (proj₂ xs) (proj₁ xs , F.id)) where |
| 68 |
|
| 69 |
m : C₁ ⇒ C₂ |
| 70 |
m .shape = λ s → proj₁ (nt (s , F.id)) |
| 71 |
m .position = proj₂ (nt (_ , F.id)) |