-
Notifications
You must be signed in to change notification settings - Fork 3
/
Variables.agda
70 lines (55 loc) · 1.81 KB
/
Variables.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Variables where
open import Data.Nat using (ℕ; zero; suc)
open import Data.Nat.Properties using (_≟_; suc-injective)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl; cong)
open import Types
infixl 5 _,_
data Context : Set where
∅ : Context
_,_ : Context → Type → Context
infix 4 _⊑*_
-- Typing context precision
data _⊑*_ : Context → Context → Set where
⊑*-∅ : ∅ ⊑* ∅
⊑*-, : ∀ {A A′ Γ Γ′}
→ A ⊑ A′
→ Γ ⊑* Γ′
→ Γ , A ⊑* Γ′ , A′
infix 4 _∋_
infix 9 S_
data _∋_ : Context → Type → Set where
Z : ∀ {Γ A}
----------
→ Γ , A ∋ A
S_ : ∀ {Γ A B}
→ Γ ∋ A
---------
→ Γ , B ∋ A
∋→ℕ : ∀{Γ}{A} → Γ ∋ A → ℕ
∋→ℕ {.(_ , A)} {A} Z = 0
∋→ℕ {.(_ , _)} {A} (S Γ∋A) = suc (∋→ℕ Γ∋A)
var-eq? : ∀ {Γ A}
→ (x₁ x₂ : Γ ∋ A)
→ Dec (x₁ ≡ x₂)
var-eq? Z Z = yes refl
var-eq? Z (S _) = no λ ()
var-eq? (S _) Z = no λ ()
var-eq? (S x₁) (S x₂) with var-eq? x₁ x₂
... | yes x₁≡x₂ = yes (cong S_ x₁≡x₂)
... | no x₁≢x₂ = no λ { refl → x₁≢x₂ refl }
⊑*→⊑ : ∀ {Γ Γ′ A A′}
→ (x : Γ ∋ A) → (x′ : Γ′ ∋ A′)
→ Γ ⊑* Γ′
→ ∋→ℕ x ≡ ∋→ℕ x′
-----------------
→ A ⊑ A′
⊑*→⊑ Z Z (⊑*-, lp lpc) refl = lp
⊑*→⊑ (S x) (S x′) (⊑*-, _ lpc) eq = ⊑*→⊑ x x′ lpc (suc-injective eq)
∋→ℕ-lookup-same : ∀ {Γ A B}
→ (x : Γ ∋ A) → (y : Γ ∋ B)
→ ∋→ℕ x ≡ ∋→ℕ y
---------------------------
→ A ≡ B
∋→ℕ-lookup-same Z Z refl = refl
∋→ℕ-lookup-same (S x) (S y) eq = ∋→ℕ-lookup-same x y (suc-injective eq)