-
Notifications
You must be signed in to change notification settings - Fork 28
/
stlc.stt
165 lines (126 loc) · 5.68 KB
/
stlc.stt
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
-- Embedded Church-coded STLC
--------------------------------------------------------------------------------
Ty : U
= (Ty : U)
(nat top bot : Ty)
(arr prod sum : Ty → Ty → Ty)
→ Ty
nat : Ty = λ _ nat _ _ _ _ _. nat
top : Ty = λ _ _ top _ _ _ _. top
bot : Ty = λ _ _ _ bot _ _ _. bot
arr : Ty → Ty → Ty
= λ A B Ty nat top bot arr prod sum.
arr (A Ty nat top bot arr prod sum) (B Ty nat top bot arr prod sum)
prod : Ty → Ty → Ty
= λ A B Ty nat top bot arr prod sum.
prod (A Ty nat top bot arr prod sum) (B Ty nat top bot arr prod sum)
sum : Ty → Ty → Ty
= λ A B Ty nat top bot arr prod sum.
sum (A Ty nat top bot arr prod sum) (B Ty nat top bot arr prod sum)
Con : U
= (Con : U)
(nil : Con)
(snoc : Con → Ty → Con)
→ Con
nil : Con
= λ Con nil snoc. nil
snoc : Con → Ty → Con
= λ Γ A Con nil snoc. snoc (Γ Con nil snoc) A
Var : Con → Ty → U
= λ Γ A.
(Var : Con → Ty → U)
(vz : {Γ A} → Var (snoc Γ A) A)
(vs : {Γ B A} → Var Γ A → Var (snoc Γ B) A)
→ Var Γ A
vz : {Γ A} → Var (snoc Γ A) A
= λ Var vz vs. vz
vs : {Γ B A} → Var Γ A → Var (snoc Γ B) A
= λ x Var vz vs. vs (x Var vz vs)
Tm : Con → Ty → U
= λ Γ A.
(Tm : Con → Ty → U)
(var : {Γ A} → Var Γ A → Tm Γ A)
(lam : {Γ A B} → Tm (snoc Γ A) B → Tm Γ (arr A B))
(app : {Γ A B} → Tm Γ (arr A B) → Tm Γ A → Tm Γ B)
(tt : {Γ} → Tm Γ top)
(pair : {Γ A B} → Tm Γ A → Tm Γ B → Tm Γ (prod A B))
(fst : {Γ A B} → Tm Γ (prod A B) → Tm Γ A)
(snd : {Γ A B} → Tm Γ (prod A B) → Tm Γ B)
(left : {Γ A B} → Tm Γ A → Tm Γ (sum A B))
(right : {Γ A B} → Tm Γ B → Tm Γ (sum A B))
(case : {Γ A B C} → Tm Γ (sum A B) → Tm Γ (arr A C) → Tm Γ (arr B C) → Tm Γ C)
(zero : {Γ} → Tm Γ nat)
(suc : {Γ} → Tm Γ nat → Tm Γ nat)
(rec : {Γ A} → Tm Γ nat → Tm Γ (arr nat (arr A A)) → Tm Γ A → Tm Γ A)
→ Tm Γ A
var : {Γ A} → Var Γ A → Tm Γ A
= λ x Tm var lam app tt pair fst snd left right case zero suc rec.
var x
lam : {Γ A B} → Tm (snoc Γ A) B → Tm Γ (arr A B)
= λ t Tm var lam app tt pair fst snd left right case zero suc rec.
lam (t Tm var lam app tt pair fst snd left right case zero suc rec)
app : {Γ A B} → Tm Γ (arr A B) → Tm Γ A → Tm Γ B
= λ t u Tm var lam app tt pair fst snd left right case zero suc rec.
app (t Tm var lam app tt pair fst snd left right case zero suc rec)
(u Tm var lam app tt pair fst snd left right case zero suc rec)
tt : {Γ} → Tm Γ top
= λ Tm var lam app tt pair fst snd left right case zero suc rec. tt
pair : {Γ A B} → Tm Γ A → Tm Γ B → Tm Γ (prod A B)
= λ t u Tm var lam app tt pair fst snd left right case zero suc rec.
pair (t Tm var lam app tt pair fst snd left right case zero suc rec)
(u Tm var lam app tt pair fst snd left right case zero suc rec)
fst : {Γ A B} → Tm Γ (prod A B) → Tm Γ A
= λ t Tm var lam app tt pair fst snd left right case zero suc rec.
fst (t Tm var lam app tt pair fst snd left right case zero suc rec)
snd : {Γ A B} → Tm Γ (prod A B) → Tm Γ B
= λ t Tm var lam app tt pair fst snd left right case zero suc rec.
snd (t Tm var lam app tt pair fst snd left right case zero suc rec)
left : {Γ A B} → Tm Γ A → Tm Γ (sum A B)
= λ t Tm var lam app tt pair fst snd left right case zero suc rec.
left (t Tm var lam app tt pair fst snd left right case zero suc rec)
right : {Γ A B} → Tm Γ B → Tm Γ (sum A B)
= λ t Tm var lam app tt pair fst snd left right case zero suc rec.
right (t Tm var lam app tt pair fst snd left right case zero suc rec)
case : {Γ A B C} → Tm Γ (sum A B) → Tm Γ (arr A C) → Tm Γ (arr B C) → Tm Γ C
= λ t u v Tm var lam app tt pair fst snd left right case zero suc rec.
case (t Tm var lam app tt pair fst snd left right case zero suc rec)
(u Tm var lam app tt pair fst snd left right case zero suc rec)
(v Tm var lam app tt pair fst snd left right case zero suc rec)
zero : {Γ} → Tm Γ nat
= λ Tm var lam app tt pair fst snd left right case zero suc rec. zero
suc : {Γ} → Tm Γ nat → Tm Γ nat
= λ t Tm var lam app tt pair fst snd left right case zero suc rec.
suc (t Tm var lam app tt pair fst snd left right case zero suc rec)
rec : {Γ A} → Tm Γ nat → Tm Γ (arr nat (arr A A)) → Tm Γ A → Tm Γ A
= λ t u v Tm var lam app tt pair fst snd left right case zero suc rec.
rec (t Tm var lam app tt pair fst snd left right case zero suc rec)
(u Tm var lam app tt pair fst snd left right case zero suc rec)
(v Tm var lam app tt pair fst snd left right case zero suc rec)
v0 : {Γ A} → Tm (snoc Γ A) A
= var vz
v1 : {Γ A B} → Tm (snoc (snoc Γ A) B) A
= var (vs vz)
v2 : {Γ A B C} → Tm (snoc (snoc (snoc Γ A) B) C) A
= var (vs (vs vz))
v3 : {Γ A B C D} → Tm (snoc (snoc (snoc (snoc Γ A) B) C) D) A
= var (vs (vs (vs vz)))
tbool : Ty = sum top top
true : {Γ} → Tm Γ tbool
= left tt
tfalse : {Γ} → Tm Γ tbool
= right tt
ifthenelse : {Γ A} → Tm Γ (arr tbool (arr A (arr A A)))
= lam (lam (lam (case v2 (lam v2) (lam v1))))
times4 : {Γ A} → Tm Γ (arr (arr A A) (arr A A))
= lam (lam (app v1 (app v1 (app v1 (app v1 v0)))))
add : {Γ} → Tm Γ (arr nat (arr nat nat))
= lam (rec v0
(lam (lam (lam (suc (app v1 v0)))))
(lam v0))
mul : {Γ} → Tm Γ (arr nat (arr nat nat))
= lam (rec v0
(lam (lam (lam (app (app add (app v1 v0)) v0))))
(lam zero))
fact : {Γ} → Tm Γ (arr nat nat)
= lam (rec v0 (lam (lam (app (app mul (suc v1)) v0)))
(suc zero))