author | wenzelm |
Mon, 20 Aug 2012 13:58:06 +0200 | |
changeset 48863 | 881e8a96e617 |
parent 38460 | 628fee3eb449 |
permissions | -rw-r--r-- |
34156
3a7937841585
Changes in generated code, apparently caused by changes to the code generation system itself.
paulson
parents:
33707
diff
changeset
|
1 |
structure Example : sig |
38460 | 2 |
val fold : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b |
34156
3a7937841585
Changes in generated code, apparently caused by changes to the code generation system itself.
paulson
parents:
33707
diff
changeset
|
3 |
val rev : 'a list -> 'a list |
3a7937841585
Changes in generated code, apparently caused by changes to the code generation system itself.
paulson
parents:
33707
diff
changeset
|
4 |
datatype 'a queue = AQueue of 'a list * 'a list |
3a7937841585
Changes in generated code, apparently caused by changes to the code generation system itself.
paulson
parents:
33707
diff
changeset
|
5 |
val empty : 'a queue |
3a7937841585
Changes in generated code, apparently caused by changes to the code generation system itself.
paulson
parents:
33707
diff
changeset
|
6 |
val dequeue : 'a queue -> 'a option * 'a queue |
3a7937841585
Changes in generated code, apparently caused by changes to the code generation system itself.
paulson
parents:
33707
diff
changeset
|
7 |
val enqueue : 'a -> 'a queue -> 'a queue |
3a7937841585
Changes in generated code, apparently caused by changes to the code generation system itself.
paulson
parents:
33707
diff
changeset
|
8 |
end = struct |
28421 | 9 |
|
48863 | 10 |
fun fold f (x :: xs) s = fold f xs (f x s) |
11 |
| fold f [] s = s; |
|
38460 | 12 |
|
13 |
fun rev xs = fold (fn a => fn b => a :: b) xs []; |
|
28421 | 14 |
|
29798 | 15 |
datatype 'a queue = AQueue of 'a list * 'a list; |
28421 | 16 |
|
33707
68841fb382e0
dropped obsolete documentation; updated generated sources
haftmann
parents:
30226
diff
changeset
|
17 |
val empty : 'a queue = AQueue ([], []); |
28421 | 18 |
|
29798 | 19 |
fun dequeue (AQueue ([], [])) = (NONE, AQueue ([], [])) |
20 |
| dequeue (AQueue (xs, y :: ys)) = (SOME y, AQueue (xs, ys)) |
|
21 |
| dequeue (AQueue (v :: va, [])) = |
|
28421 | 22 |
let |
23 |
val y :: ys = rev (v :: va); |
|
24 |
in |
|
29798 | 25 |
(SOME y, AQueue ([], ys)) |
28421 | 26 |
end; |
27 |
||
29798 | 28 |
fun enqueue x (AQueue (xs, ys)) = AQueue (x :: xs, ys); |
28421 | 29 |
|
30 |
end; (*struct Example*) |