removed itlist, rev_itlist -- use fold_rev, fold instead;
authorwenzelm
Thu, 14 Jul 2005 19:28:39 +0200
changeset 16854 fdd362b7e980
parent 16853 33b886cbdc8f
child 16855 7563d0eb3414
removed itlist, rev_itlist -- use fold_rev, fold instead; improved end_itlist;
TFL/utils.ML
--- a/TFL/utils.ML	Thu Jul 14 19:28:38 2005 +0200
+++ b/TFL/utils.ML	Thu Jul 14 19:28:39 2005 +0200
@@ -10,8 +10,6 @@
 sig
   exception ERR of {module: string, func: string, mesg: string}
   val C: ('a -> 'b -> 'c) -> 'b -> 'a -> 'c
-  val itlist: ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
-  val rev_itlist: ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
   val end_itlist: ('a -> 'a -> 'a) -> 'a list -> 'a
   val itlist2: ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c
   val pluck: ('a -> bool) -> 'a list -> 'a * 'a list
@@ -30,26 +28,9 @@
 
 fun C f x y = f y x
 
-fun itlist f L base_value =
-   let fun it [] = base_value
-         | it (a::rst) = f a (it rst)
-   in it L
-   end;
-
-fun rev_itlist f =
-   let fun rev_it [] base = base
-         | rev_it (a::rst) base = rev_it rst (f a base)
-   in rev_it
-   end;
-
-fun end_itlist f =
-   let fun endit [] = raise UTILS_ERR "end_itlist" "list too short"
-         | endit alist =
-            let val (base::ralist) = rev alist
-            in itlist f (rev ralist) base
-            end
-   in endit
-   end;
+fun end_itlist f [] = raise (UTILS_ERR "end_itlist" "list too short")
+  | end_itlist f [x] = x 
+  | end_itlist f (x :: xs) = f x (end_itlist f xs);
 
 fun itlist2 f L1 L2 base_value =
  let fun it ([],[]) = base_value