]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/lib/cps.ml
drgOutput: bug fix
[helm.git] / helm / software / lambda-delta / lib / cps.ml
index e42faba498aa4b0806e4264f0b0099d67f9f6e30..aa0dbc7c1f2ac756599e765ee1f2d9298ade3987 100644 (file)
@@ -20,18 +20,21 @@ let rec list_sub_strict f l1 l2 = match l1, l2 with
    | _ :: tl1, _ :: tl2 -> list_sub_strict f tl1 tl2
    | _                  -> assert false
 
+(* this is not tail recursive *)
 let rec list_fold_left f map a = function
    | []       -> f a
    | hd :: tl -> 
       let f a = list_fold_left f map a tl in
       map f a hd
 
+(* this is not tail recursive *)
 let rec list_rev_map_append f map ~tail = function
       | []       -> f tail        
       | hd :: tl ->
          let f hd = list_rev_map_append f map ~tail:(hd :: tail) tl in
          map f hd
 
+(* this is not tail recursive *)
 let rec list_forall2 f map l1 l2 = match l1, l2 with
    | [], []                 -> f true
    | hd1 :: tl1, hd2 :: tl2 ->
@@ -48,17 +51,11 @@ let list_rev_map =
 let list_rev =
    list_rev_append ~tail:[]
 
-let list_fold_right f map l a =
-   let map f a m = map f m a in
-   list_rev (list_fold_left f map a) l
-
-let list_map f =
-   list_rev_map (list_rev f)
-   
 let list_iter f map l =
    let map f () x = map f x in
    list_fold_left f map () l
 
+(* this is not tail recursive *)
 let rec list_fold_left2 f map a l1 l2 = match l1, l2 with
    | [], []                 -> f a
    | hd1 :: tl1, hd2 :: tl2 -> 
@@ -70,6 +67,18 @@ let list_iter2 f map l1 l2 =
    let map f () x1 x2 = map f x1 x2 in
    list_fold_left2 f map () l1 l2
 
+let rec list_fold_right f map l a = match l with
+   | []       -> f a
+   | hd :: tl ->
+      let f a = map f hd a in
+      list_fold_right f map tl a
+
+let list_map f map l =
+   let map f hd a = 
+      let f hd = f (hd :: a) in map f hd
+   in
+   list_fold_right f map l []
+
 let rec list_mem ?(eq=(=)) a = function
    | []                   -> false
    | hd :: _ when eq a hd -> true