-
Notifications
You must be signed in to change notification settings - Fork 0
/
erasure.agda
178 lines (169 loc) · 8.42 KB
/
erasure.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
175
176
177
178
open import prelude
open import core
open import hazelnut.untyped.zexp
module hazelnut.untyped.erasure where
-- judgmental cursor erasure
data erase-τ : (τ^ : ZTyp) → (τ : Typ) → Set where
ETTop : ∀ {τ} → erase-τ (▹ τ ◃) τ
ETArr1 : ∀ {τ₁^ τ₂ τ₁} → (τ₁^◇ : erase-τ τ₁^ τ₁) → erase-τ (τ₁^ -→₁ τ₂) (τ₁ -→ τ₂)
ETArr2 : ∀ {τ₁ τ₂^ τ₂} → (τ₂^◇ : erase-τ τ₂^ τ₂) → erase-τ (τ₁ -→₂ τ₂^) (τ₁ -→ τ₂)
ETProd1 : ∀ {τ₁^ τ₂ τ₁} → (τ₁^◇ : erase-τ τ₁^ τ₁) → erase-τ (τ₁^ -×₁ τ₂) (τ₁ -× τ₂)
ETProd2 : ∀ {τ₁ τ₂^ τ₂} → (τ₂^◇ : erase-τ τ₂^ τ₂) → erase-τ (τ₁ -×₂ τ₂^) (τ₁ -× τ₂)
data erase-e : (ê : ZExp) → (e : UExp) → Set where
EETop : ∀ {e}
→ erase-e (‵▹ e ◃) e
EELam1 : ∀ {x τ^ e τ}
→ (τ^◇ : erase-τ τ^ τ)
→ erase-e (‵λ₁ x ∶ τ^ ∙ e) (‵λ x ∶ τ ∙ e)
EELam2 : ∀ {x τ ê e}
→ (ê◇ : erase-e ê e)
→ erase-e (‵λ₂ x ∶ τ ∙ ê) (‵λ x ∶ τ ∙ e)
EEAp1 : ∀ {ê₁ e₂ e₁}
→ (ê₁◇ : erase-e ê₁ e₁)
→ erase-e (‵ ê₁ ∙₁ e₂) (‵ e₁ ∙ e₂)
EEAp2 : ∀ {e₁ ê₂ e₂}
→ (ê₂◇ : erase-e ê₂ e₂)
→ erase-e (‵ e₁ ∙₂ ê₂) (‵ e₁ ∙ e₂)
EELet1 : ∀ {x ê₁ e₂ e₁}
→ (ê₁◇ : erase-e ê₁ e₁)
→ erase-e (‵ x ←₁ ê₁ ∙ e₂) (‵ x ← e₁ ∙ e₂)
EELet2 : ∀ {x e₁ ê₂ e₂}
→ (ê₂◇ : erase-e ê₂ e₂)
→ erase-e (‵ x ←₂ e₁ ∙ ê₂) (‵ x ← e₁ ∙ e₂)
EEPlus1 : ∀ {ê₁ e₂ e₁}
→ (ê₁◇ : erase-e ê₁ e₁)
→ erase-e (‵ ê₁ +₁ e₂) (‵ e₁ + e₂)
EEPlus2 : ∀ {e₁ ê₂ e₂}
→ (ê₂◇ : erase-e ê₂ e₂)
→ erase-e (‵ e₁ +₂ ê₂) (‵ e₁ + e₂)
EEIf1 : ∀ {ê₁ e₂ e₃ e₁}
→ (ê₁◇ : erase-e ê₁ e₁)
→ erase-e (‵ ê₁ ∙₁ e₂ ∙ e₃) (‵ e₁ ∙ e₂ ∙ e₃)
EEIf2 : ∀ {e₁ ê₂ e₃ e₂}
→ (ê₂◇ : erase-e ê₂ e₂)
→ erase-e (‵ e₁ ∙₂ ê₂ ∙ e₃) (‵ e₁ ∙ e₂ ∙ e₃)
EEIf3 : ∀ {e₁ e₂ ê₃ e₃}
→ (ê₃◇ : erase-e ê₃ e₃)
→ erase-e (‵ e₁ ∙₃ e₂ ∙ ê₃) (‵ e₁ ∙ e₂ ∙ e₃)
EEPair1 : ∀ {ê₁ e₂ e₁}
→ (ê₁◇ : erase-e ê₁ e₁)
→ erase-e (‵⟨ ê₁ ,₁ e₂ ⟩) (‵⟨ e₁ , e₂ ⟩)
EEPair2 : ∀ {e₁ ê₂ e₂}
→ (ê₂◇ : erase-e ê₂ e₂)
→ erase-e (‵⟨ e₁ ,₂ ê₂ ⟩) (‵⟨ e₁ , e₂ ⟩)
EEProjL : ∀ {ê e}
→ (ê◇ : erase-e ê e)
→ erase-e (‵π₁ ê) (‵π₁ e)
EEProjR : ∀ {ê e}
→ (ê◇ : erase-e ê e)
→ erase-e (‵π₂ ê) (‵π₂ e)
-- functional cursor erasure
_◇τ : (τ^ : ZTyp) → Typ
▹ τ ◃ ◇τ = τ
(τ^ -→₁ τ) ◇τ = (τ^ ◇τ) -→ τ
(τ -→₂ τ^) ◇τ = τ -→ (τ^ ◇τ)
(τ^ -×₁ τ) ◇τ = (τ^ ◇τ) -× τ
(τ -×₂ τ^) ◇τ = τ -× (τ^ ◇τ)
_◇ : (ê : ZExp) → UExp
‵▹ e ◃ ◇ = e
(‵λ₁ x ∶ τ^ ∙ e) ◇ = ‵λ x ∶ (τ^ ◇τ) ∙ e
(‵λ₂ x ∶ τ ∙ ê) ◇ = ‵λ x ∶ τ ∙ (ê ◇)
(‵ ê ∙₁ e) ◇ = ‵ (ê ◇) ∙ e
(‵ e ∙₂ ê) ◇ = ‵ e ∙ (ê ◇)
(‵ x ←₁ ê ∙ e) ◇ = ‵ x ← (ê ◇) ∙ e
(‵ x ←₂ e ∙ ê) ◇ = ‵ x ← e ∙ (ê ◇)
(‵ ê +₁ e) ◇ = ‵ (ê ◇) + e
(‵ e +₂ ê) ◇ = ‵ e + (ê ◇)
(‵ ê ∙₁ e₂ ∙ e₃) ◇ = ‵ (ê ◇) ∙ e₂ ∙ e₃
(‵ e₁ ∙₂ ê ∙ e₃) ◇ = ‵ e₁ ∙ (ê ◇) ∙ e₃
(‵ e₁ ∙₃ e₂ ∙ ê) ◇ = ‵ e₁ ∙ e₂ ∙ (ê ◇)
‵⟨ ê₁ ,₁ e₂ ⟩ ◇ = ‵⟨ ê₁ ◇ , e₂ ⟩
‵⟨ e₁ ,₂ ê₂ ⟩ ◇ = ‵⟨ e₁ , ê₂ ◇ ⟩
(‵π₁ ê) ◇ = ‵π₁ (ê ◇)
(‵π₂ ê) ◇ = ‵π₂ (ê ◇)
-- convert judgmental cursor erasure to functional cursor erasure
erase-τ→◇ : ∀ {τ^ τ} → erase-τ τ^ τ → τ^ ◇τ ≡ τ
erase-τ→◇ ETTop = refl
erase-τ→◇ (ETArr1 τ₁^◇)
rewrite erase-τ→◇ τ₁^◇ = refl
erase-τ→◇ (ETArr2 τ₂^◇)
rewrite erase-τ→◇ τ₂^◇ = refl
erase-τ→◇ (ETProd1 τ₁^◇)
rewrite erase-τ→◇ τ₁^◇ = refl
erase-τ→◇ (ETProd2 τ₂^◇)
rewrite erase-τ→◇ τ₂^◇ = refl
erase-e→◇ : ∀ {ê e} → erase-e ê e → ê ◇ ≡ e
erase-e→◇ EETop = refl
erase-e→◇ (EELam1 τ^◇)
rewrite erase-τ→◇ τ^◇ = refl
erase-e→◇ (EELam2 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEAp1 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEAp2 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EELet1 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EELet2 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEPlus1 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEPlus2 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEIf1 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEIf2 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEIf3 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEPair1 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEPair2 ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEProjL ê◇)
rewrite erase-e→◇ ê◇ = refl
erase-e→◇ (EEProjR ê◇)
rewrite erase-e→◇ ê◇ = refl
-- convert functional cursor erasure to judgmental cursor erasure
◇τ→erase : ∀ {τ^ τ} → τ^ ◇τ ≡ τ → erase-τ τ^ τ
◇τ→erase {▹ τ ◃} refl = ETTop
◇τ→erase {τ₁^ -→₁ τ₂} refl
with τ₁^◇ ← ◇τ→erase {τ₁^} {τ₁^ ◇τ} refl = ETArr1 τ₁^◇
◇τ→erase {τ₁ -→₂ τ₂^} refl
with τ₂^◇ ← ◇τ→erase {τ₂^} {τ₂^ ◇τ} refl = ETArr2 τ₂^◇
◇τ→erase {τ₁^ -×₁ τ₂} refl
with τ₁^◇ ← ◇τ→erase {τ₁^} {τ₁^ ◇τ} refl = ETProd1 τ₁^◇
◇τ→erase {τ₁ -×₂ τ₂^} refl
with τ₂^◇ ← ◇τ→erase {τ₂^} {τ₂^ ◇τ} refl = ETProd2 τ₂^◇
◇e→erase : ∀ {ê e} → ê ◇ ≡ e → erase-e ê e
◇e→erase {‵▹ e ◃} refl = EETop
◇e→erase {‵λ₁ x ∶ τ^ ∙ e} refl
with τ^◇ ← ◇τ→erase {τ^} {τ^ ◇τ} refl = EELam1 τ^◇
◇e→erase {‵λ₂ x ∶ τ ∙ ê} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EELam2 ê◇
◇e→erase {‵ ê ∙₁ e} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEAp1 ê◇
◇e→erase {‵ e ∙₂ ê} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEAp2 ê◇
◇e→erase {‵ x ←₁ ê ∙ e} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EELet1 ê◇
◇e→erase {‵ x ←₂ e ∙ ê} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EELet2 ê◇
◇e→erase {‵ ê +₁ e} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEPlus1 ê◇
◇e→erase {‵ e +₂ ê} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEPlus2 ê◇
◇e→erase {‵ ê ∙₁ e₂ ∙ e₃} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEIf1 ê◇
◇e→erase {‵ e₁ ∙₂ ê ∙ e₃} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEIf2 ê◇
◇e→erase {‵ e₁ ∙₃ e₂ ∙ ê} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEIf3 ê◇
◇e→erase {‵⟨ ê ,₁ e₂ ⟩} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEPair1 ê◇
◇e→erase {‵⟨ e₁ ,₂ ê ⟩} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEPair2 ê◇
◇e→erase {‵π₁ ê} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEProjL ê◇
◇e→erase {‵π₂ ê} refl
with ê◇ ← ◇e→erase {ê} {ê ◇} refl = EEProjR ê◇