aux 0 l
;;
+let sharing_map f l =
+ let unchanged = ref true in
+ let rec aux b = function
+ | [] as t -> unchanged := b; t
+ | he::tl ->
+ let he1 = f he in
+ he1 :: aux (b && he1 == he) tl
+ in
+ let l1 = aux true l in
+ if !unchanged then l else l1
+;;
+
let rec list_uniq ?(eq=(=)) = function
| [] -> []
| h::[] -> [h]
val flatten_map: ('a -> 'b list) -> 'a list -> 'b list
val list_last: 'a list -> 'a
val list_mapi: ('a -> int -> 'b) -> 'a list -> 'b list
+val sharing_map: ('a -> 'a) -> 'a list -> 'a list
(** split_nth n l
* @returns two list, the first contains at least n elements, the second the