equal
deleted
inserted
replaced
255 | rep (n, xs) = rep (n - 1, x :: xs) |
255 | rep (n, xs) = rep (n - 1, x :: xs) |
256 in |
256 in |
257 if n < 0 then raise LIST "replicate" |
257 if n < 0 then raise LIST "replicate" |
258 else rep (n, []) |
258 else rep (n, []) |
259 end; |
259 end; |
|
260 |
|
261 (*multiply [a, b, c, ...] * [xs, ys, zs, ...]*) |
|
262 fun multiply ([], _) = [] |
|
263 | multiply (x :: xs, yss) = map (cons x) yss @ multiply (xs, yss); |
260 |
264 |
261 |
265 |
262 (* filter *) |
266 (* filter *) |
263 |
267 |
264 (*copy the list preserving elements that satisfy the predicate*) |
268 (*copy the list preserving elements that satisfy the predicate*) |
779 (* handle errors capturing messages *) |
783 (* handle errors capturing messages *) |
780 |
784 |
781 datatype 'a error = |
785 datatype 'a error = |
782 Error of string | |
786 Error of string | |
783 OK of 'a; |
787 OK of 'a; |
|
788 |
|
789 fun get_error (Error msg) = Some msg |
|
790 | get_error _ = None; |
|
791 |
|
792 fun get_ok (OK x) = Some x |
|
793 | get_ok _ = None; |
784 |
794 |
785 fun handle_error f x = |
795 fun handle_error f x = |
786 let |
796 let |
787 val buffer = ref ""; |
797 val buffer = ref ""; |
788 fun capture s = buffer := ! buffer ^ s ^ "\n"; |
798 fun capture s = buffer := ! buffer ^ s ^ "\n"; |