-
Notifications
You must be signed in to change notification settings - Fork 1
/
BidirectionalTypeChecking-stub.agda
192 lines (119 loc) · 3.62 KB
/
BidirectionalTypeChecking-stub.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
-- Agda teaser in DAT151/DIT231 Programming Language Technology 2016
-- Andreas Abel (partially plagiarized from Ulf Norell's ICFP 2013 talk)
-- St. Lucia 2016-12-13
-- Prelude
------------------------------------------------------------------------
-- Basic types
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
data List (A : Set) : Set where
[] : List A
_∷_ : (x : A) (xs : List A) → List A
-- Hello World
-- Basic propositions
------------------------------------------------------------------------
-- Conjunction
record _×_ (A B : Set) : Set where
-- Implication
modusPonens : ∀{A B} → A × (A → B) → B
modusPonens = {!!}
-- Disjuction
data _⊎_ (A B : Set) : Set where
-- A tautology involving disjunction
taut : ∀{A B} → (A → B) → A ⊎ B → B
taut = {!!}
-- Truth
record ⊤ : Set where
-- Absurdity
data ⊥ : Set where
⊥-elim : {A : Set} → ⊥ → A
⊥-elim = {!!}
¬ : (A : Set) → Set
¬ A = A → ⊥
-- Contraposition
contra : ∀{A B} → (A → B) → ¬ B → ¬ A
contra = {!!}
-- Decidable propositions
data Dec (P : Set) : Set where
-- Equality
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
_≢_ : {A : Set} (x y : A) → Set
x ≢ y = ¬ (x ≡ y)
-- Simply-typed lambda-calculus
------------------------------------------------------------------------
-- Types
data Ty : Set where
base : Ty
_⇒_ : (a b : Ty) → Ty
-- Type equality is propositional equality
-- Injectivity properties
⇒≠base : ∀{a b} → (a ⇒ b) ≡ base → ⊥
⇒≠base = {!!}
⇒injl : ∀{a b c d} → (a ⇒ c) ≡ (b ⇒ d) → a ≡ b
⇒injl = {!!}
⇒injr : ∀{a b c d} → (a ⇒ c) ≡ (b ⇒ d) → c ≡ d
⇒injr = {!!}
-- Deciding type equality
eqTy : (a b : Ty) → Dec (a ≡ b)
eqTy = {!!}
-- Raw de Bruijn terms
data Exp : Set where
-- Typing contexts
Cxt = List Ty
-- Bidirectional typing
------------------------------------------------------------------------
-- Well typed well-scoped variables
--
-- _⊢var_:_ ⊆ Cxt × ℕ × Ty
--
-- Γ ⊢var x : a
-- vz -------------- vs ----------------
-- Γ,a ⊢var 0 : a Γ,b ⊢var 1+x : a
data Var : (Γ : Cxt) (x : ℕ) (a : Ty) → Set where
-- Typing judgements
--
-- Inference _⊢ne_:_ ⊆ Cxt × Exp × Ty (neutral expressions)
-- Checking _⊢nf_:_ ⊆ Cxt × Exp × Ty (normal forms)
--
-- Γ ⊢var x : b Γ ⊢ne f : a ⇒ b Γ ⊢nf e : a
-- neVar ------------------ neApp ------------------------------
-- Γ ⊢ne (var x) : b Γ ⊢ne (app f e) : b
--
-- Γ,a ⊢nf e : b Γ ⊢ne e : a
-- nfAbs ---------------------- nfNe ------------
-- Γ ⊢nf abs e : a ⇒ b Γ ⊢nf e : a
mutual
data Ne (Γ : Cxt) : (e : Exp) (b : Ty) → Set where
data Nf (Γ : Cxt) : (e : Exp) (a : Ty) → Set where
-- Type checking algorithm
------------------------------------------------------------------------
-- Sound context lookup
data Lookup (Γ : Cxt) (x : ℕ) : Set where
lookupVar : ∀ Γ (x : ℕ) → Lookup Γ x
lookupVar = {!!}
-- Sound type checking
-- Result of type checking
data Infer (Γ : Cxt) (e : Exp) : Set where
data Check (Γ : Cxt) (e : Exp) (a : Ty) : Set where
-- Inference rules
-- Variable
inferVar : {!!}
inferVar = {!!}
-- Application
inferApp : {!!}
inferApp = {!!}
-- Checking rules
-- Neutrals
checkNe : {!!}
checkNe = {!!}
-- Abstraction
checkAbs : {!!}
checkAbs = {!!}
-- Sound type-checker
mutual
check : ∀ Γ e a → Check Γ e a
check Γ e a = {!!}
infer : ∀ Γ e → Infer Γ e
infer Γ e = {!!}