-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd.disp
73 lines (65 loc) · 1.84 KB
/
std.disp
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
context type {
// The type of all programs, takes a program and returns `*` (i.e. unbound variable) to signify that typechecking was successful.
type := [_] *
}
context combinators {
z := λf.(λx.f (λy.x x y)) (λx.f (λy.x x y))
}
context type_system {
// Pi type is the dependent type constructor. It is the type of all functions.
pi_type := [bind bind_type out_type] pair (pair bind bind_type) out_type
// App type is the application type constructor. It is the type of application
app_type := [left right] pair left right
uni := [order] single order
uni0 := uni zero
uni1 := uni (succ zero)
check := [expr type]
}
context expr {
encode {
expr := type
var := [v l a] v : expr
lambda := [bind] [expr] [v l a] l bind expr : expr
app := [func] [args] [v l a] a func args : expr
binding := type
none := [v l a] v : binding
branch := [bind] [expr] [v l a] l bind expr : binding
end := [n b e] e : binding
}
}
context bool {
context encode church_encoding {
bool := type
true := [first second] first : bool
false := [first second] second : bool
if := [bool] [then_expr] [else_expr] bool then_expr else_expr
}
}
context nat {
context encode church_encoding {
zero := [f x] x
succ := [n] [f x] f (n f x)
}
context ops {
iszero := [n] n ([u] false) (true)
add := [m n] [f x] m f (n f x)
mult := [m n] [f] m (n f)
pred := [n] [f x] n ([g h] h (g f)) ([u] x) ([u] u)
factorial := [n] n ([x] x ([x y] pair (succ x) (mult x y))) (pair 1 1) second
}
}
context pair encode church_encoding {
pair := [first second] [func] func first second
first := [pair] pair true
second := [pair] pair true
}
context single encode church_encoding {
single := [single] [func] func single
first := [single] single [x] x
}
context list encode {
nil := [func] func
cons := [head tail] [func] func head tail
car := first
cdr := second
}