diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util.ml | 13 | ||||
-rw-r--r-- | lib/util.mli | 7 |
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/util.ml b/lib/util.ml index 5a5905859..4089dc03d 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -42,6 +42,11 @@ let located_iter2 f (_,a) (_,b) = f a b exception Error_in_file of string * (bool * string * loc) * exn +(* Mapping under pairs *) + +let on_fst f (a,b) = (f a,b) +let on_snd f (a,b) = (a,f b) + (* Projections from triplets *) let pi1 (a,_,_) = a @@ -552,6 +557,13 @@ let list_unique_index x = | [] -> raise Not_found in index_x 1 +let list_fold_right_i f i l = + let rec it_list_f i l a = match l with + | [] -> a + | b::l -> f (i-1) b (it_list_f (i-1) l a) + in + it_list_f (List.length l + i) l + let list_fold_left_i f = let rec it_list_f i a = function | [] -> a @@ -1169,6 +1181,7 @@ let pr_semicolon () = str ";" ++ spc () let pr_bar () = str "|" ++ spc () let pr_arg pr x = spc () ++ pr x let pr_opt pr = function None -> mt () | Some x -> pr_arg pr x +let pr_opt_no_spc pr = function None -> mt () | Some x -> pr x let nth n = str (ordinal n) diff --git a/lib/util.mli b/lib/util.mli index e715feca3..bc1a9cc26 100644 --- a/lib/util.mli +++ b/lib/util.mli @@ -52,6 +52,11 @@ val located_iter2 : ('a -> 'b -> unit) -> 'a located -> 'b located -> unit exception Error_in_file of string * (bool * string * loc) * exn +(* Mapping under pairs *) + +val on_fst : ('a -> 'b) -> 'a * 'c -> 'b * 'c +val on_snd : ('a -> 'b) -> 'c * 'a -> 'c * 'b + (*s Projections from triplets *) val pi1 : 'a * 'b * 'c -> 'a @@ -121,6 +126,7 @@ val list_unique_index : 'a -> 'a list -> int val list_index0 : 'a -> 'a list -> int val list_iter3 : ('a -> 'b -> 'c -> unit) -> 'a list -> 'b list -> 'c list -> unit val list_iter_i : (int -> 'a -> unit) -> 'a list -> unit +val list_fold_right_i : (int -> 'a -> 'b -> 'b) -> int -> 'a list -> 'b -> 'b val list_fold_left_i : (int -> 'a -> 'b -> 'a) -> int -> 'a -> 'b list -> 'a val list_fold_right_and_left : ('a -> 'b -> 'b list -> 'a) -> 'b list -> 'a -> 'a @@ -257,6 +263,7 @@ val pr_semicolon : unit -> std_ppcmds val pr_bar : unit -> std_ppcmds val pr_arg : ('a -> std_ppcmds) -> 'a -> std_ppcmds val pr_opt : ('a -> std_ppcmds) -> 'a option -> std_ppcmds +val pr_opt_no_spc : ('a -> std_ppcmds) -> 'a option -> std_ppcmds val nth : int -> std_ppcmds val prlist : ('a -> std_ppcmds) -> 'a list -> std_ppcmds |