equal
deleted
inserted
replaced
149 make (fn () => |
149 make (fn () => |
150 (case pull xq of |
150 (case pull xq of |
151 NONE => pull yq |
151 NONE => pull yq |
152 | SOME (x, xq') => SOME (x, interleave (yq, xq')))); |
152 | SOME (x, xq') => SOME (x, interleave (yq, xq')))); |
153 |
153 |
154 |
154 (*print a sequence, up to "count" elements*) |
155 (*functional to print a sequence, up to "count" elements; |
155 fun print print_elem count = |
156 the function prelem should print the element number and also the element*) |
156 let |
157 fun print prelem count seq = |
157 fun prnt k xq = |
158 let |
|
159 fun pr (k, xq) = |
|
160 if k > count then () |
158 if k > count then () |
161 else |
159 else |
162 (case pull xq of |
160 (case pull xq of |
163 NONE => () |
161 NONE => () |
164 | SOME (x, xq') => (prelem k x; writeln ""; pr (k + 1, xq'))) |
162 | SOME (x, xq') => (print_elem k x; writeln ""; prnt (k + 1) xq')); |
165 in pr (1, seq) end; |
163 in prnt 1 end; |
166 |
164 |
167 (*accumulating a function over a sequence; this is lazy*) |
165 (*accumulating a function over a sequence; this is lazy*) |
168 fun it_right f (xq, yq) = |
166 fun it_right f (xq, yq) = |
169 let |
167 let |
170 fun its s = |
168 fun its s = |