-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.shen
89 lines (58 loc) · 1.75 KB
/
misc.shen
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
(tc -) \\ untyped
\\ system patch
(package shen [&]
(define map-expr
F [] -> []
F [L|R] -> [(F L) | (map-expr F R)]
F X -> (F X))
(define prterm
[cons X Y] -> (do (pr "[") (prterm X) (prtl Y) (pr "]"))
[F | X] -> (do (pr "(") (prterm F) (map-expr (/. Y (do (pr " ") (prterm Y))) X) (pr ")"))
X -> (print X))
)
(tc +)
\\ typed
\\ unit module
(datatype @unit@
__________________________
unit : unit;)
\\ option module
(datatype @verified@
P : verified >> X : T;
Y : T;
________________________________________________
(if P X Y) : T;
_________________________________________________
X : A >> X : (- (? A));
X : A;
_________________________________________________
X : (- (? A));
_________________________________________________
X : (? A), (!? X) : verified >> X : A;
____________________________________________________
? : (? A);)
(define !?
{ A --> boolean }
X -> (not (== ? X)))
\\ fake alist module
(synonyms (alist.alist K V) (list (K * V)))
(define alist.value
{ A --> (alist.alist A B) --> (? B) }
A [] -> ?
A [(@p A B)|XS] -> B
A [_|XS] -> (alist.value A XS))
(define alist.set
{ A --> B --> (alist.alist A B) --> (alist.alist A B) }
K V XS -> [(@p K V) | XS])
(define alist.foldl
{ (C --> A --> B --> C) --> (alist.alist A B) --> C --> C }
F [] C -> C
F [(@p A B)|XS] C -> (alist.foldl F XS (F C A B)))
\\ list
(define foldl
{ (B --> A --> B) --> (list A) --> B --> B }
F [] B -> B
F [X|XS] B -> (foldl F XS (F B X)))
(datatype @unify@
_______________________
(unify X X);)