aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar filliatr <filliatr@85f007b7-540e-0410-9357-904b9bb8a0f7>1999-08-18 15:20:08 +0000
committerGravatar filliatr <filliatr@85f007b7-540e-0410-9357-904b9bb8a0f7>1999-08-18 15:20:08 +0000
commitfeabced9caa5996738d1c51fec8428623ebf0fd6 (patch)
treeae6090c645840c195ed8005b51b2793ef0669939 /lib
parentce1b28cfe404cce72f14012a7c2b7d4c866fb9b3 (diff)
module Reduction (fin)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@14 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'lib')
-rw-r--r--lib/util.ml35
-rw-r--r--lib/util.mli6
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/util.ml b/lib/util.ml
index 77a26062d..4370b4cb9 100644
--- a/lib/util.ml
+++ b/lib/util.ml
@@ -91,6 +91,31 @@ let list_assign l n e =
in
assrec [] (l,n)
+let rec list_distinct = function
+ | h::t -> (not (List.mem h t)) && list_distinct t
+ | [] -> true
+
+let list_map_i f =
+ let rec map_i_rec i = function
+ | [] -> []
+ | x::l -> let v = f i x in v :: map_i_rec (i+1) l
+ in
+ map_i_rec
+
+let list_index x =
+ let rec index_x n = function
+ | y::l -> if x = y then n else index_x (succ n) l
+ | [] -> failwith "index"
+ in
+ index_x 1
+
+let list_fold_left_i f =
+ let rec it_list_f i a = function
+ | [] -> a
+ | b::l -> it_list_f (i+1) (f i a b) l
+ in
+ it_list_f
+
(* Arrays *)
let array_exists f v =
@@ -132,6 +157,16 @@ let array_last v =
let array_cons e v = Array.append [|e|] v
+let array_fold_left2 f a v1 v2 =
+ let lv1 = Array.length v1 in
+ let rec fold a n =
+ if n >= lv1 then a else fold (f a v1.(n) v2.(n)) (succ n)
+ in
+ if Array.length v2 <> lv1 then
+ invalid_arg "array_fold_left2"
+ else
+ fold a 0
+
let array_fold_left_from n f a v =
let rec fold a n =
if n >= Array.length v then a else fold (f a v.(n)) (succ n)
diff --git a/lib/util.mli b/lib/util.mli
index c539bdf67..73a33dbad 100644
--- a/lib/util.mli
+++ b/lib/util.mli
@@ -27,6 +27,10 @@ val subtract : 'a list -> 'a list -> 'a list
val list_chop : int -> 'a list -> 'a list * 'a list
val list_tabulate : (int -> 'a) -> int -> 'a list
val list_assign : 'a list -> int -> 'a -> 'a list
+val list_distinct : 'a list -> bool
+val list_map_i : (int -> 'a -> 'b) -> int -> 'a list -> 'b list
+val list_index : 'a -> 'a list -> int
+val list_fold_left_i : (int -> 'a -> 'b -> 'a) -> int -> 'a -> 'b list -> 'a
(* Arrays *)
@@ -37,6 +41,8 @@ val array_hd : 'a array -> 'a
val array_tl : 'a array -> 'a array
val array_last : 'a array -> 'a
val array_cons : 'a -> 'a array -> 'a array
+val array_fold_left2 :
+ ('a -> 'b -> 'c -> 'a) -> 'a -> 'b array -> 'c array -> 'a
val array_fold_left_from : int -> ('a -> 'b -> 'a) -> 'a -> 'b array -> 'a
val array_fold_right_from : int -> ('a -> 'b -> 'b) -> 'a array -> 'b -> 'b
val array_app_tl : 'a array -> 'a list -> 'a list