-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariants.agda
56 lines (43 loc) · 1.68 KB
/
Variants.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{-# OPTIONS --safe #-}
module ROmega.IndexCalculus.Variants where
open import Agda.Primitive
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans)
open import Data.Sum
renaming (_⊎_ to _or_; inj₁ to left; inj₂ to right)
hiding (map)
open import Data.Product
using (_×_; ∃; ∃-syntax; Σ-syntax; _,_)
renaming (proj₁ to fst; proj₂ to snd)
open import Data.Fin renaming (zero to fzero; suc to fsuc)
open import ROmega.IndexCalculus.Rows
--------------------------------------------------------------------------------
-- Variants say: "Of the types in this row, I can give you exactly one."
Σ : ∀ {ℓ} → Row (Set ℓ) → Set ℓ
Σ (n , P) = Σ[ i ∈ Fin n ] (P i)
--------------------------------------------------------------------------------
-- injection.
inj : ∀ {ℓ} (z y : Row {lsuc ℓ} (Set ℓ)) (w : z ≲ y) (s : Σ z) → Σ y
inj {ℓ} z y w (n , P) with w n
... | m , Q rewrite Q = m , P
--------------------------------------------------------------------------------
-- Variant branching.
infixl 5 _▿_
infixl 5 _▿_Using_
_▿_ : ∀ {ℓ} {x y z : Row {lsuc ℓ} (Set ℓ)}
{C : Set}
{x·y~z : x · y ~ z}
(E-Σx : Σ x → C)
(E-Σy : Σ y → C) →
Σ z → C
_▿_ {ℓ} {x} {y} {z} {C} {x·y~z} E-Σx E-Σy (iz , Pz) with fst x·y~z iz
... | left (ix , Px) rewrite (sym Px) = E-Σx (ix , Pz)
... | right (iy , Py) rewrite (sym Py) = E-Σy (iy , Pz)
_▿_Using_ :
∀ {ℓ} {x y z : Row {lsuc ℓ} (Set ℓ)}
{C : Set}
(E-Σx : Σ x → C)
(E-Σy : Σ y → C)
(x·y~z : x · y ~ z) →
Σ z → C
(E-Σx ▿ E-Σy Using x·y~z) = (_▿_) {x·y~z = x·y~z} E-Σx E-Σy