24193
|
1 |
structure HOL =
|
|
2 |
struct
|
|
3 |
|
|
4 |
fun leta s f = f s;
|
|
5 |
|
|
6 |
end; (*struct HOL*)
|
|
7 |
|
21190
|
8 |
structure Nat =
|
21147
|
9 |
struct
|
|
10 |
|
24421
|
11 |
datatype nat = Suc of nat | Zero_nat;
|
21147
|
12 |
|
26318
|
13 |
fun less_nat m (Suc n) = less_eq_nat m n
|
21994
|
14 |
| less_nat n Zero_nat = false
|
26318
|
15 |
and less_eq_nat (Suc m) n = less_nat m n
|
|
16 |
| less_eq_nat Zero_nat n = true;
|
21147
|
17 |
|
21994
|
18 |
fun minus_nat (Suc m) (Suc n) = minus_nat m n
|
|
19 |
| minus_nat Zero_nat n = Zero_nat
|
22751
|
20 |
| minus_nat m Zero_nat = m;
|
21147
|
21 |
|
25056
|
22 |
end; (*struct Nat*)
|
24193
|
23 |
|
25056
|
24 |
structure Product_Type =
|
|
25 |
struct
|
|
26 |
|
26513
|
27 |
fun split f (a, b) = f a b;
|
25056
|
28 |
|
|
29 |
end; (*struct Product_Type*)
|
21147
|
30 |
|
|
31 |
structure Codegen =
|
|
32 |
struct
|
|
33 |
|
|
34 |
fun pick ((k, v) :: xs) n =
|
21994
|
35 |
(if Nat.less_nat n k then v else pick xs (Nat.minus_nat n k))
|
|
36 |
| pick (x :: xs) n =
|
|
37 |
let
|
25056
|
38 |
val a = x;
|
|
39 |
val (k, v) = a;
|
21994
|
40 |
in
|
|
41 |
(if Nat.less_nat n k then v else pick xs (Nat.minus_nat n k))
|
|
42 |
end;
|
21147
|
43 |
|
|
44 |
end; (*struct Codegen*)
|