-
Notifications
You must be signed in to change notification settings - Fork 0
/
mler.8.sml
194 lines (147 loc) · 4.44 KB
/
mler.8.sml
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
datatype 'a list
= Empty
| Cons of 'a * 'a list;
Empty;
Cons (10, Cons (20, Empty));
datatype orapl =
Apple
| Orange;
fun eq_orapl (Orange, Orange)
= true
| eq_orapl (Apple, Apple)
= true
| eq_orapl (a, b)
= false;
fun eq_int (n:int, m:int):bool = (n = m);
fun subst_int (n, a, Empty)
= Empty
| subst_int (n, a, Cons (x, y))
= if (eq_int (a, x))
then Cons (n, subst_int (n, a, y))
else Cons (x, subst_int (n, a, y));
subst_int (99, 10, Cons (10, Cons (20, Cons (10, Cons (30, Empty)))));
fun subst_orapl (n, a, Empty)
= Empty
| subst_orapl (n, a, Cons (x, y))
= if (eq_orapl (a, x))
then Cons (n, subst_orapl (n, a, y))
else Cons (x, subst_orapl (n, a, y));
subst_orapl (Orange, Apple,
Cons (Apple,
Cons (Apple,
Cons (Apple,
Cons (Orange, Empty)))));
fun subst (rel, n, a, Empty)
= Empty
| subst (rel, n, a, Cons (x, y))
= if (rel (a, x))
then Cons (n, subst (rel, n, a, y))
else Cons (x, subst (rel, n, a, y));
subst (eq_orapl, Orange, Apple,
Cons (Apple,
Cons (Apple,
Cons (Apple,
Cons (Orange, Empty)))));
fun less_than (x, y) = x < y;
fun in_range ((small, large), x)
= if less_than (small, x)
then less_than (x, large)
else false;
fun subst_pred (pred, n, Empty)
= Empty
| subst_pred (pred, n, Cons (x, y))
= if (pred (x))
then Cons (n, subst_pred (pred, n, y))
else Cons (x, subst_pred (pred, n, y));
fun is_apple (x)
= eq_orapl (Apple, x);
subst_pred (is_apple, Orange,
Cons (Apple,
Cons (Apple,
Cons (Apple,
Cons (Orange, Empty)))));
fun less_than_15 (x)
= less_than (x, 15);
subst_pred (less_than_15, 11,
Cons (15,
Cons (6,
Cons (15,
Cons (17,
Cons (15,
Cons (8, Empty)))))));
fun in_range_11_16 (x)
= if less_than (11, x)
then less_than (x, 16)
else false;
subst_pred (in_range_11_16, 11,
Cons (15,
Cons (6,
Cons (15,
Cons (17,
Cons (15,
Cons (8, Empty)))))));
fun in_range_c (small, large) (x)
= if less_than (small, x)
then less_than (x, large)
else false;
subst_pred (in_range_c (11, 16), 22,
Cons (15,
Cons (6,
Cons (15,
Cons (17,
Cons (15,
Cons (8, Empty)))))));
fun subst_pred_curry (pred) (n, Empty)
= Empty
| subst_pred_curry (pred) (n, Cons (x, y))
= if (pred (x))
then Cons (n, subst_pred_curry (pred) (n, y))
else Cons (x, subst_pred_curry (pred) (n, y));
fun subst_c (pred)
= fn (n, Empty)
=> Empty
| (n, Cons (e, t))
=> if (pred (e))
then Cons (n, subst_c (pred) (n, t))
else Cons (e, subst_c (pred) (n, t));
fun combine (Empty, x)
= x
| combine (Cons (a, l1), x)
= Cons (a, combine (l1, x));
combine (Cons (1,
Cons (2,
Cons (3, Empty))),
Cons (5,
Cons (4,
Cons (7,
Cons (9, Empty)))));
fun combine_c (Empty) (x)
= x
| combine_c (Cons (a, l1)) (x)
= Cons (a, combine_c (l1) (x));
combine_c (Cons (1,
Cons (2,
Cons (3, Empty))))
(Cons (5,
Cons (4,
Cons (7,
Cons (9, Empty)))));
fun prefixer_123 (l)
= Cons (1,
Cons (2,
Cons (3, l)));
prefixer_123 (combine_c (Cons (1,
Cons (2,
Cons (3, Empty))))
(Cons (5,
Cons (4,
Cons (7,
Cons (9, Empty))))));
combine_c (Cons (1,
Cons (2,
Cons (3, Empty))));
fun waiting_prefix_123 (l)
= Cons (1,
combine_c (Cons (2,
Cons (3, Empty)))
(l));