Source

ocaml-lib / lSet.ml

Diff from to
-(** Sets as ordered polymorphic lists. *)
+(**
+   Sets as ordered polymorphic lists.
+
+   Author: S-Aébastien Ferré-b
+   License: LGPL
+*)
 
 include List
 
 let remove : 'a -> 'a list -> 'a list =
   fun x l -> subtract l [x]
 
-(* partition par the belonging to a set *)
+(* partition by the belonging to a set *)
 (* partitioner -> partitionee -> inter * diff *)
-      let rec partition_set : 'a t -> 'a t -> 'a t * 'a t =
-	fun l1 l2 -> match l1, l2 with
-	| [], l2 -> [], l2
-	| _, [] -> [], []
-	| x1::l1, x2::l2 ->
-	    let comp = compare x1 x2 in
-	    if comp < 0 then
-	      partition_set l1 (x2::l2)
-	    else if comp > 0 then
-	      let inter, diff = partition_set (x1::l1) l2 in
-	      inter, x2::diff
-	    else
-	      let inter, diff = partition_set l1 l2 in
-	      x2::inter, diff
+let rec partition_set : 'a t -> 'a t -> 'a t * 'a t =
+  fun l1 l2 -> match l1, l2 with
+  | [], l2 -> [], l2
+  | _, [] -> [], []
+  | x1::l1, x2::l2 ->
+      let comp = compare x1 x2 in
+      if comp < 0 then
+	partition_set l1 (x2::l2)
+      else if comp > 0 then
+	let inter, diff = partition_set (x1::l1) l2 in
+	inter, x2::diff
+      else
+	let inter, diff = partition_set l1 l2 in
+	x2::inter, diff
 
 (** Remove an element if present, add it otherwise. *)
 let rec flip : 'a -> 'a list -> 'a list =
 
 
 (*
-   iterative functions on lists can also be applied, at least in some cases
+   iterative functions on lists can also be applied, provided they preserve the order of lists
 *)