Permalink
Browse files

Move eq/comp/ord out of Incubator, remove List.make_compare

  • Loading branch information...
1 parent 2727343 commit c6eaef8ad34474cc845356c4d8112d9fada4ea4d @thelema thelema committed Mar 18, 2012
Showing with 234 additions and 253 deletions.
  1. +7 −6 src/batIMap.ml
  2. +36 −40 src/batList.ml
  3. +14 −15 src/batList.mli
  4. +123 −130 src/batTuple.ml
  5. +51 −59 src/batTuple.mli
  6. +2 −2 testsuite/test_map.ml
  7. +1 −1 testsuite/test_set.ml
View
@@ -274,12 +274,13 @@ let empty ~eq = {m = Core.empty; eq}
let is_empty {m} = Core.is_empty m
let add x y {m;eq} = {m=Core.add ~eq x y m; eq}
-(*$= add as a & ~cmp:(List.Incubator.eq (Tuple3.Incubator.eq Int.eq Int.eq Int.eq)) ~printer:(List.print (Tuple3.print Int.print Int.print Int.print) |> IO.to_string)
- [(0,2,0)] (empty ~eq:(=) |> a 0 0 |> a 2 0 |> a 1 0 |> enum |> List.of_enum)
- *)
-(*$= add as a & ~cmp:(List.Incubator.eq (Tuple3.Incubator.eq Int.eq Int.eq String.eq)) ~printer:(List.print (Tuple3.print Int.print Int.print String.print) |> IO.to_string)
- [(0,2,"foo")] (empty ~eq:(=) |> a 0 "foo" |> a 2 "foo" |> a 1 "foo" |> enum |> List.of_enum)
- *)
+(*$= add as a & ~cmp:(List.eq (Tuple3.eq Int.eq Int.eq Int.eq)) ~printer:(List.print (Tuple3.print Int.print Int.print Int.print) |> IO.to_string)
+ [(0,2,0)] (empty ~eq:(=) |> a 0 0 |> a 2 0 |> a 1 0 |> enum |> List.of_enum)
+*)
+(*$= add as a & ~cmp:(List.eq (Tuple3.eq Int.eq Int.eq String.eq)) ~printer:(List.print (Tuple3.print Int.print Int.print String.print) |> IO.to_string)
+ [(0,2,"foo")] \
+ (empty ~eq:(=) |> a 0 "foo" |> a 2 "foo" |> a 1 "foo" |> enum |> List.of_enum)
+*)
let add_range lo hi y {m;eq} = {m=Core.add_range ~eq lo hi y m; eq}
View
@@ -867,47 +867,43 @@ module Infix = struct
let ( @ ) = ( @ )
end
-module Incubator = struct
- open BatOrd
-
- let rec eq eq_elt l1 l2 =
- match l1 with
- | [] -> (match l2 with [] -> true | _ -> false)
- | hd1::tl1 ->
- (match l2 with
- | [] -> false
- | hd2::tl2 -> bin_eq eq_elt hd1 hd2 (eq eq_elt) tl1 tl2)
-
- let rec ord ord_elt l1 l2 =
- match l1 with
- | [] -> (match l2 with [] -> Eq | _::_ -> Lt)
- | hd1::tl1 ->
- (match l2 with
- | [] -> Gt
- | hd2::tl2 -> bin_ord ord_elt hd1 hd2 (ord ord_elt) tl1 tl2)
-
- let rec comp comp_elt l1 l2 =
- match l1 with
- | [] -> (match l2 with [] -> 0 | _::_ -> -1)
- | hd1::tl1 ->
- (match l2 with
- | [] -> 1
- | hd2::tl2 -> bin_comp comp_elt hd1 hd2 (comp comp_elt) tl1 tl2)
-
- module Eq (T : Eq) = struct
- type t = T.t list
- let eq = eq T.eq
- end
+open BatOrd
- module Ord (T : Ord) = struct
- type t = T.t list
- let ord = ord T.ord
- end
+let rec eq eq_elt l1 l2 =
+ match l1 with
+ | [] -> (match l2 with [] -> true | _ -> false)
+ | hd1::tl1 ->
+ (match l2 with
+ | [] -> false
+ | hd2::tl2 -> bin_eq eq_elt hd1 hd2 (eq eq_elt) tl1 tl2)
- module Comp (T : Comp) = struct
- type t = T.t list
- let compare = comp T.compare
- end
+let rec ord ord_elt l1 l2 =
+ match l1 with
+ | [] -> (match l2 with [] -> Eq | _::_ -> Lt)
+ | hd1::tl1 ->
+ (match l2 with
+ | [] -> Gt
+ | hd2::tl2 -> bin_ord ord_elt hd1 hd2 (ord ord_elt) tl1 tl2)
+
+let rec comp comp_elt l1 l2 =
+ match l1 with
+ | [] -> (match l2 with [] -> 0 | _::_ -> -1)
+ | hd1::tl1 ->
+ (match l2 with
+ | [] -> 1
+ | hd2::tl2 -> bin_comp comp_elt hd1 hd2 (comp comp_elt) tl1 tl2)
+
+module Eq (T : Eq) = struct
+ type t = T.t list
+ let eq = eq T.eq
end
-let make_compare c = Incubator.comp c
+module Ord (T : Ord) = struct
+ type t = T.t list
+ let ord = ord T.ord
+end
+
+module Comp (T : Comp) = struct
+ type t = T.t list
+ let compare = comp T.compare
+end
View
@@ -515,10 +515,6 @@ val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
Not tail-recursive (sum of the lengths of the arguments).
*)
-val make_compare : ('a -> 'a -> int) -> 'a list -> 'a list -> int
-(** [make_compare c] generates the lexicographical order on lists
-induced by [c]*)
-
val sort_unique : ('a -> 'a -> int) -> 'a list -> 'a list
(** [sort_unique cmp l] returns the list [l] sorted and without any duplicate
element. [cmp] is a usual comparison function providing total order.
@@ -565,6 +561,20 @@ BatInnerIO.output -> 'b -> unit) -> 'a BatInnerIO.output -> 'b list -> unit
val t_printer : 'a BatValuePrinter.t -> 'a t BatValuePrinter.t
+open BatOrd
+val eq : 'a eq -> 'a list eq
+val ord : 'a ord -> 'a list ord
+val comp : 'a comp -> 'a list comp
+
+(** Comparison and equality for lists based on element comparison and
+ equality *)
+
+module Eq (T : Eq) : Eq with type t = T.t list
+module Ord (T : Ord) : Ord with type t = T.t list
+module Comp (T : Comp) : Comp with type t = T.t list
+
+
+
(** {6 Obsolete functions} *)
val nth : 'a list -> int -> 'a
@@ -715,14 +725,3 @@ end
val ( @ ) : 'a list -> 'a list -> 'a list
(** Tail recursive [List.append]. *)
-
-module Incubator : sig
- open BatOrd
- val eq : 'a eq -> 'a list eq
- val ord : 'a ord -> 'a list ord
- val comp : 'a comp -> 'a list comp
-
- module Eq (T : Eq) : Eq with type t = T.t list
- module Ord (T : Ord) : Ord with type t = T.t list
- module Comp (T : Comp) : Comp with type t = T.t list
-end
Oops, something went wrong.

0 comments on commit c6eaef8

Please sign in to comment.