Debian Codegraph @

src/Data/Container/Core.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Containers core
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Container.Core where
10
11 open import Level using (Level; _⊔_; suc)
12 open import Data.Product.Base as Product using (Σ-syntax)
13 open import Function.Base using (_∘_; _∘′_)
14 open import Function.Bundles using (Inverse; _↔_)
15 open import Relation.Unary using (Pred; _⊆_)
16
17 -- Definition of Containers
18
19 infix 5 _▷_
20 record Container (s p : Level) : Set (suc (s ⊔ p)) where
21 constructor _▷_
22 field
23 Shape : Set s
24 Position : Shape → Set p
25 open Container public
26
27 -- The semantics ("extension") of a container.
28
29 ⟦_⟧ : ∀ {s p ℓ} → Container s p → Set ℓ → Set (s ⊔ p ⊔ ℓ)
30 ⟦ S ▷ P ⟧ X = Σ[ s ∈ S ] (P s → X)
31
32 -- The extension is a functor
33
34 map : ∀ {s p x y} {C : Container s p} {X : Set x} {Y : Set y} →
35 (X → Y) → ⟦ C ⟧ X → ⟦ C ⟧ Y
36 map f = Product.map₂ (f ∘_)
37
38 -- Representation of container morphisms.
39
40 infixr 8 _⇒_ _⊸_
41
42 record _⇒_ {s₁ s₂ p₁ p₂} (C₁ : Container s₁ p₁) (C₂ : Container s₂ p₂)
43 : Set (s₁ ⊔ s₂ ⊔ p₁ ⊔ p₂) where
44 constructor _▷_
45 field
46 shape : Shape C₁ → Shape C₂
47 position : ∀ {s} → Position C₂ (shape s) → Position C₁ s
48
49 ⟪_⟫ : ∀ {x} {X : Set x} → ⟦ C₁ ⟧ X → ⟦ C₂ ⟧ X
50 ⟪_⟫ = Product.map shape (_∘′ position)
51
52 open _⇒_ public
53
54 -- Linear container morphisms
55
56 record _⊸_ {s₁ s₂ p₁ p₂} (C₁ : Container s₁ p₁) (C₂ : Container s₂ p₂)
57 : Set (s₁ ⊔ s₂ ⊔ p₁ ⊔ p₂) where
58 field
59 shape⊸ : Shape C₁ → Shape C₂
60 position⊸ : ∀ {s} → Position C₂ (shape⊸ s) ↔ Position C₁ s
61
62 morphism : C₁ ⇒ C₂
63 morphism = record
64 { shape = shape⊸
65 ; position = Inverse.to position⊸
66 }
67
68 ⟪_⟫⊸ : ∀ {x} {X : Set x} → ⟦ C₁ ⟧ X → ⟦ C₂ ⟧ X
69 ⟪_⟫⊸ = ⟪ morphism ⟫
70
71 open _⊸_ public using (shape⊸; position⊸; ⟪_⟫⊸)