-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUExp.agda
151 lines (122 loc) · 5.52 KB
/
UExp.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
open import Data.Nat using (ℕ)
open import Data.List using (List)
open import Data.List.Relation.Unary.All using (All)
open import Data.Product using (_×_; _,_; ∃-syntax)
open import Relation.Binary.PropositionalEquality using (refl; _≡_)
open import Grove.Ident
open import Grove.Marking.Var
open import Grove.Marking.STyp
open import Grove.Marking.Typ
open import Grove.Marking.Ctx
open import Grove.Marking.Grove using (Vertex; Location)
-- unmarked expressions
module Grove.Marking.UExp where
infix 4 _⊢_⇒_
infix 4 _⊢_⇐_
infix 4 _⊢s_⇒_
infix 4 _⊢s_⇐_
mutual
data UExp : Set where
-_^_ : (x : Var) → (u : VertexId) → UExp
-λ_∶_∙_^_ : (x : Var) → (τ : ChildTyp) → (e : UChildExp) → (u : VertexId) → UExp
-_∙_^_ : (e₁ : UChildExp) → (e₂ : UChildExp) → (u : VertexId) → UExp
-ℕ_^_ : (n : ℕ) → (u : VertexId) → UExp
-_+_^_ : (e₁ : UChildExp) → (e₂ : UChildExp) → (u : VertexId) → UExp
-⋎^_^_ : (w : EdgeId) → (v : Vertex) → UExp
-↻^_^_ : (w : EdgeId) → (v : Vertex) → UExp
data UChildExp : Set where
-□ : (s : Location) → UChildExp
-∶ : (ė : UChildExp') → UChildExp
-⋏ : (s : Location) → (ė* : List UChildExp') → UChildExp
UChildExp' = EdgeId × UExp
data USubsumable : UExp → Set where
USuVar : ∀ {x u}
→ USubsumable (- x ^ u)
USuAp : ∀ {e₁ e₂ u}
→ USubsumable (- e₁ ∙ e₂ ^ u)
USuNum : ∀ {n u}
→ USubsumable (-ℕ n ^ u)
USuPlus : ∀ {e₁ e₂ u}
→ USubsumable (- e₁ + e₂ ^ u)
mutual
-- synthesis
data _⊢_⇒_ : (Γ : Ctx) (e : UExp) (τ : STyp) → Set where
USVar : ∀ {Γ x u τ}
→ (∋x : Γ ∋ x ∶ τ)
→ Γ ⊢ - x ^ u ⇒ τ
USLam : ∀ {Γ x τ e u τ'}
→ (e⇒τ' : Γ , x ∶ (τ △s) ⊢s e ⇒ τ')
→ Γ ⊢ -λ x ∶ τ ∙ e ^ u ⇒ (τ △s) -→ τ'
USAp : ∀ {Γ e₁ e₂ u τ τ₁ τ₂}
→ (e₁⇒τ : Γ ⊢s e₁ ⇒ τ)
→ (τ▸ : τ ▸ τ₁ -→ τ₂)
→ (e₁⇐τ₁ : Γ ⊢s e₂ ⇐ τ₁)
→ Γ ⊢ - e₁ ∙ e₂ ^ u ⇒ τ₂
USNum : ∀ {Γ n u}
→ Γ ⊢ -ℕ n ^ u ⇒ num
USPlus : ∀ {Γ e₁ e₂ u}
→ (e₁⇐num : Γ ⊢s e₁ ⇐ num)
→ (e₂⇐num : Γ ⊢s e₂ ⇐ num)
→ Γ ⊢ - e₁ + e₂ ^ u ⇒ num
USMultiLocationConflict : ∀ {Γ w v}
→ Γ ⊢ -⋎^ w ^ v ⇒ unknown
USCycleLocationConflict : ∀ {Γ w v}
→ Γ ⊢ -↻^ w ^ v ⇒ unknown
data _⊢s_⇒_ : (Γ : Ctx) (e : UChildExp) (τ : STyp) → Set where
USHole : ∀ {Γ s}
→ Γ ⊢s -□ s ⇒ unknown
USOnly : ∀ {Γ w e τ}
→ (e⇒τ : Γ ⊢ e ⇒ τ)
→ Γ ⊢s -∶ (w , e) ⇒ τ
USLocalConflict : ∀ {Γ s ė*}
→ (ė⇒* : All (λ (_ , e) → ∃[ τ ] Γ ⊢ e ⇒ τ) ė*)
→ Γ ⊢s -⋏ s ė* ⇒ unknown
-- analysis
data _⊢_⇐_ : (Γ : Ctx) (e : UExp) (τ : STyp) → Set where
UALam : ∀ {Γ x τ e u τ₁ τ₂ τ₃}
→ (τ₃▸ : τ₃ ▸ τ₁ -→ τ₂)
→ (τ~τ₁ : (τ △s) ~ τ₁)
→ (e⇐τ₂ : Γ , x ∶ (τ △s) ⊢s e ⇐ τ₂)
→ Γ ⊢ -λ x ∶ τ ∙ e ^ u ⇐ τ₃
UAMultiLocationConflict : ∀ {Γ w v τ}
→ Γ ⊢ -⋎^ w ^ v ⇐ τ
UACycleLocationConflict : ∀ {Γ w v τ}
→ Γ ⊢ -↻^ w ^ v ⇐ τ
UASubsume : ∀ {Γ e τ τ'}
→ (e⇒τ' : Γ ⊢ e ⇒ τ')
→ (τ~τ' : τ ~ τ')
→ (su : USubsumable e)
→ Γ ⊢ e ⇐ τ
data _⊢s_⇐_ : (Γ : Ctx) (e : UChildExp) (τ : STyp) → Set where
UAHole : ∀ {Γ s τ}
→ Γ ⊢s -□ s ⇐ τ
UAOnly : ∀ {Γ w e τ}
→ (e⇐τ : Γ ⊢ e ⇐ τ)
→ Γ ⊢s -∶ (w , e) ⇐ τ
UALocalConflict : ∀ {Γ s ė* τ}
→ (ė⇐* : All (λ (_ , e) → Γ ⊢ e ⇐ τ) ė*)
→ Γ ⊢s -⋏ s ė* ⇐ τ
-- synthesis unicity
mutual
⇒-unicity : ∀ {Γ : Ctx} {e : UExp} {τ₁ τ₂ : STyp}
→ Γ ⊢ e ⇒ τ₁
→ Γ ⊢ e ⇒ τ₂
→ τ₁ ≡ τ₂
⇒-unicity (USVar ∋x) (USVar ∋x') = ∋→τ-≡ ∋x ∋x'
⇒-unicity (USLam e⇒τ₁) (USLam e⇒τ₂)
rewrite ⇒s-unicity e⇒τ₁ e⇒τ₂ = refl
⇒-unicity (USAp e₁⇒τ₁ τ▸ e₂⇐τ₂) (USAp e₁⇒τ₁' τ▸' e₂⇐τ₂')
rewrite ⇒s-unicity e₁⇒τ₁ e₁⇒τ₁'
with refl ← ▸-→-unicity τ▸ τ▸' = refl
⇒-unicity USNum USNum = refl
⇒-unicity (USPlus e₁⇐num e₂⇐num) (USPlus e₁⇐num' e₂⇐num') = refl
⇒-unicity USMultiLocationConflict USMultiLocationConflict = refl
⇒-unicity USCycleLocationConflict USCycleLocationConflict = refl
⇒s-unicity : ∀ {Γ : Ctx} {e : UChildExp} {τ₁ τ₂ : STyp}
→ Γ ⊢s e ⇒ τ₁
→ Γ ⊢s e ⇒ τ₂
→ τ₁ ≡ τ₂
⇒s-unicity USHole USHole = refl
⇒s-unicity (USOnly e⇒τ) (USOnly e⇒τ')
rewrite ⇒-unicity e⇒τ e⇒τ' = refl
⇒s-unicity (USLocalConflict ė⇒*) (USLocalConflict ė⇒*') = refl