-
Notifications
You must be signed in to change notification settings - Fork 1
/
typing.agda
174 lines (161 loc) · 5.83 KB
/
typing.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
open import common
import syntactics
import reduction
module typing
(Level : Set)
(_<_ : Level → Level → Set)
(trans< : ∀ {i j k} → i < j → j < k → i < k) where
open syntactics Level
open reduction Level
data _≤_ : Level → Level → Set where
eq : ∀ {k} → k ≤ k
lt : ∀ {j k} → j < k → j ≤ k
{------------------------
Definitional equality
------------------------}
data _≈_ : Term → Term → Set where
≈-refl : ∀ {a} → a ≈ a
≈-sym : ∀ {a b} →
b ≈ a →
---------
a ≈ b
≈-trans : ∀ {a b c} →
a ≈ b →
b ≈ c →
-----------
a ≈ c
≈-β : ∀ {b a} →
--------------------------------
$ᵈ (λᵈ b) a ≈ subst (a +: var) b
≈-ι : ∀ {d} →
------------
J d refl ≈ d
≈-Π : ∀ {a a' b b'} →
a ≈ a' →
b ≈ b' →
-------------------
Π a b ≈ Π a' b'
≈-λᵈ : ∀ {b b'} →
b ≈ b' →
------------
λᵈ b ≈ λᵈ b'
≈-$ᵈ : ∀ {b b' a a'} →
b ≈ b' →
a ≈ a' →
-----------------
$ᵈ b a ≈ $ᵈ b' a'
≈-abs : ∀ {b b'} →
b ≈ b' →
--------------
abs b ≈ abs b'
≈-eq : ∀ {A A' a a' b b'} →
A ≈ A' →
a ≈ a' →
b ≈ b' →
----------------------
eq A a b ≈ eq A' a' b'
≈-J : ∀ {d d' p p'} →
d ≈ d' →
p ≈ p' →
---------------
J d p ≈ J d' p'
-- Conversion is sound and complete with respect to definitional equality,
-- making conversion an appropriate implementation of definitional equality
⇒-≈ : ∀ {a b} → a ⇒ b → a ≈ b
⇒-≈ (⇒-β b⇒b' a⇒a') = ≈-trans (≈-$ᵈ (≈-λᵈ (⇒-≈ b⇒b')) (⇒-≈ a⇒a')) ≈-β
⇒-≈ (⇒-ι d⇒d') = ≈-trans (≈-J (⇒-≈ d⇒d') ≈-refl) ≈-ι
⇒-≈ (⇒-var s) = ≈-refl
⇒-≈ (⇒-𝒰 k) = ≈-refl
⇒-≈ (⇒-Π a⇒a' b⇒b') = ≈-Π (⇒-≈ a⇒a') (⇒-≈ b⇒b')
⇒-≈ (⇒-λᵈ b⇒b') = ≈-λᵈ (⇒-≈ b⇒b')
⇒-≈ (⇒-$ᵈ b⇒b' a⇒a') = ≈-$ᵈ (⇒-≈ b⇒b') (⇒-≈ a⇒a')
⇒-≈ ⇒-mty = ≈-refl
⇒-≈ (⇒-abs b⇒b') = ≈-abs (⇒-≈ b⇒b')
⇒-≈ (⇒-eq A⇒A' a⇒a' b⇒b') = ≈-eq (⇒-≈ A⇒A') (⇒-≈ a⇒a') (⇒-≈ b⇒b')
⇒-≈ ⇒-rfl = ≈-refl
⇒-≈ (⇒-J d⇒d' p⇒p') = ≈-J (⇒-≈ d⇒d') (⇒-≈ p⇒p')
⇒⋆-≈ : ∀ {a b} → a ⇒⋆ b → a ≈ b
⇒⋆-≈ (⇒⋆-refl a) = ≈-refl
⇒⋆-≈ (⇒⋆-trans a⇒b b⇒⋆c) = ≈-trans (⇒-≈ a⇒b) (⇒⋆-≈ b⇒⋆c)
⇔-≈ : ∀ {a b} → a ⇔ b → a ≈ b
⇔-≈ (_ , a⇒⋆c , b⇒⋆c) = ≈-trans (⇒⋆-≈ a⇒⋆c) (≈-sym (⇒⋆-≈ b⇒⋆c))
≈-⇔ : ∀ {a b} → a ≈ b → a ⇔ b
≈-⇔ ≈-refl = ⇔-refl
≈-⇔ (≈-sym b≈a) = ⇔-sym (≈-⇔ b≈a)
≈-⇔ (≈-trans a≈b b≈c) = ⇔-trans (≈-⇔ a≈b) (≈-⇔ b≈c)
≈-⇔ ≈-β = ⇒-⇔ (⇒-β (⇒-refl _) (⇒-refl _))
≈-⇔ ≈-ι = ⇒-⇔ (⇒-ι (⇒-refl _))
≈-⇔ (≈-Π a≈a' b≈b') = ⇔-Π (≈-⇔ a≈a') (≈-⇔ b≈b')
≈-⇔ (≈-λᵈ b≈b') = ⇔-λᵈ (≈-⇔ b≈b')
≈-⇔ (≈-$ᵈ b≈b' a≈a') = ⇔-$ᵈ (≈-⇔ b≈b') (≈-⇔ a≈a')
≈-⇔ (≈-abs b≈b') = ⇔-abs (≈-⇔ b≈b')
≈-⇔ (≈-eq A≈A' a≈a' b≈b') = ⇔-eq (≈-⇔ A≈A') (≈-⇔ a≈a') (≈-⇔ b≈b')
≈-⇔ (≈-J d≈d' p≈p') = ⇔-J (≈-⇔ d≈d') (≈-⇔ p≈p')
{--------------------------------------------------
Context well-formedness and term well-typedness
--------------------------------------------------}
infix 10 ⊢_
data ⊢_ : Ctxt → Set
data _⊢_⦂_ (Γ : Ctxt) : Term → Term → Set
data ⊢_ where
⊢∙ : ⊢ ∙
⊢∷ : ∀ {Γ A k} →
⊢ Γ →
Γ ⊢ A ⦂ 𝒰 k →
---------------
⊢ Γ ∷ A
data _⊢_⦂_ Γ where
⊢var : ∀ {x A} →
⊢ Γ →
x ⦂ A ∈ Γ →
-------------
Γ ⊢ var x ⦂ A
⊢𝒰 : ∀ {j k} → ⊢ Γ →
j < k →
---------------
Γ ⊢ 𝒰 j ⦂ 𝒰 k
⊢Π : ∀ {A B k} →
Γ ⊢ A ⦂ 𝒰 k →
Γ ∷ A ⊢ B ⦂ 𝒰 k →
-----------------
Γ ⊢ Π A B ⦂ 𝒰 k
⊢λᵈ : ∀ {A B b k} →
Γ ⊢ Π A B ⦂ 𝒰 k →
Γ ∷ A ⊢ b ⦂ B →
----------------
Γ ⊢ λᵈ b ⦂ Π A B
⊢$ᵈ : ∀ {A B b a} →
Γ ⊢ b ⦂ Π A B →
Γ ⊢ a ⦂ A →
-------------------------------
Γ ⊢ $ᵈ b a ⦂ subst (a +: var) B
⊢mty : ∀ {k} → ⊢ Γ →
---------------
Γ ⊢ mty ⦂ 𝒰 k
⊢abs : ∀ {A b k} →
Γ ⊢ A ⦂ 𝒰 k →
Γ ⊢ b ⦂ mty →
-------------
Γ ⊢ abs b ⦂ A
⊢eq : ∀ {A a b k} →
Γ ⊢ A ⦂ 𝒰 k →
Γ ⊢ a ⦂ A →
Γ ⊢ b ⦂ A →
-------------------
Γ ⊢ eq A a b ⦂ 𝒰 k
⊢refl : ∀ {A a} →
Γ ⊢ a ⦂ A →
-------------------
Γ ⊢ refl ⦂ eq A a a
⊢J : ∀ {A a b p d B k} →
Γ ⊢ p ⦂ eq A a b →
Γ ∷ A ∷ eq (rename suc A) (rename suc a) (var 0) ⊢ B ⦂ 𝒰 k →
Γ ⊢ d ⦂ subst (refl +: a +: var) B →
------------------------------------
Γ ⊢ J d p ⦂ subst (p +: b +: var) B
⊢≈ : ∀ {A B a k} →
A ≈ B →
Γ ⊢ a ⦂ A →
Γ ⊢ B ⦂ 𝒰 k →
-------------
Γ ⊢ a ⦂ B