if !unchanged then l else l1
;;
+let sharing_map_acc f acc l =
+ let unchanged = ref true in
+ let final_acc = ref acc in
+ let rec aux b acc = function
+ | [] as t -> unchanged := b; final_acc := acc; t
+ | he::tl ->
+ let acc, he1 = f acc he in
+ he1 :: aux (b && he1 == he) acc tl
+ in
+ let l1 = aux true acc l in
+ !final_acc, if !unchanged then l else l1
+;;
+
let rec list_uniq ?(eq=(=)) = function
| [] -> []
| h::[] -> [h]
(* Finds the zero based index of the first element that satisfies a predicate*)
val list_index: ('a -> bool) -> 'a list -> (int * 'a) option
val sharing_map: ('a -> 'a) -> 'a list -> 'a list
+val sharing_map_acc:
+ ('acc -> 'a -> 'acc * 'a) -> 'acc -> 'a list -> 'acc * 'a list
(* Iters in parallel on two lists until the first list is empty.
The second one can be shorter and is padded with a default value.
This function cannot fail. *)