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