diff --git a/src/core/CCOrd.ml b/src/core/CCOrd.ml index c8bf3f28..5b238eec 100644 --- a/src/core/CCOrd.ml +++ b/src/core/CCOrd.ml @@ -25,16 +25,16 @@ let equiv i j = not (equiv 1 0) *) -let int_ (x:int) y = Pervasives.compare x y -let string_ (x:string) y = Pervasives.compare x y -let bool_ (x:bool) y = Pervasives.compare x y -let float_ (x:float) y = Pervasives.compare x y +let int (x:int) y = Pervasives.compare x y +let string (x:string) y = Pervasives.compare x y +let bool (x:bool) y = Pervasives.compare x y +let float (x:float) y = Pervasives.compare x y (*$T - bool_ true false > 0 - bool_ false true < 0 - bool_ true true = 0 - bool_ false false = 0 + bool true false > 0 + bool false true < 0 + bool true true = 0 + bool false false = 0 *) (** {2 Lexicographic Combination} *) @@ -51,7 +51,7 @@ let option c o1 o2 = match o1, o2 with | Some x1, Some x2 -> c x1 x2 (*$Q - Q.(option int) (fun o -> option int_ None o <= 0) + Q.(option int) (fun o -> option int None o <= 0) *) let pair o_x o_y (x1,y1) (x2,y2) = @@ -61,9 +61,9 @@ let pair o_x o_y (x1,y1) (x2,y2) = else c (*$T - pair int_ string_ (1, "b") (2, "a") < 0 - pair int_ string_ (1, "b") (0, "a") > 0 - pair int_ string_ (1, "b") (1, "b") = 0 + pair int string (1, "b") (2, "a") < 0 + pair int string (1, "b") (0, "a") > 0 + pair int string (1, "b") (1, "b") = 0 *) let triple o_x o_y o_z (x1,y1,z1) (x2,y2,z2) = @@ -76,28 +76,28 @@ let triple o_x o_y o_z (x1,y1,z1) (x2,y2,z2) = else c' else c -let rec list_ ord l1 l2 = match l1, l2 with +let rec list ord l1 l2 = match l1, l2 with | [], [] -> 0 | [], _ -> -1 | _, [] -> 1 | x1::l1', x2::l2' -> let c = ord x1 x2 in if c = 0 - then list_ ord l1' l2' + then list ord l1' l2' else c (*$T - list_ int_ [1;2;3] [1;2;3;4] < 0 - list_ int_ [1;2;3;4] [1;2;3] > 0 - list_ int_ [1;2;3;4] [1;3;4] < 0 + list int [1;2;3] [1;2;3;4] < 0 + list int [1;2;3;4] [1;2;3] > 0 + list int [1;2;3;4] [1;3;4] < 0 *) (*$Q - Q.(pair (list int)(list int)) (fun (l1,l2) -> \ - equiv (list_ int_ l1 l2) (Pervasives.compare l1 l2)) + Q.(pair (list int)(list int)) CCOrd.(fun (l1,l2) -> \ + equiv (list int l1 l2) (Pervasives.compare l1 l2)) *) -let array_ ord a1 a2 = +let array ord a1 a2 = let rec aux i = if i = Array.length a1 then if Array.length a1 = Array.length a2 then 0 @@ -112,14 +112,14 @@ let array_ ord a1 a2 = aux 0 (*$T - array_ int_ [|1;2;3|] [|1;2;3;4|] < 0 - array_ int_ [|1;2;3;4|] [|1;2;3|] > 0 - array_ int_ [|1;2;3;4|] [|1;3;4|] < 0 + array int [|1;2;3|] [|1;2;3;4|] < 0 + array int [|1;2;3;4|] [|1;2;3|] > 0 + array int [|1;2;3;4|] [|1;3;4|] < 0 *) (*$Q & ~small:(fun (a1, a2) -> Array.length a1+Array.length a2) - Q.(pair (array int)(array int)) (fun (a1,a2) -> \ - equiv (array_ int_ a1 a2) (list_ int_ (Array.to_list a1) (Array.to_list a2))) + Q.(pair (array int)(array int)) CCOrd.(fun (a1,a2) -> \ + equiv (array int a1 a2) (list int (Array.to_list a1) (Array.to_list a2))) *) let map f ord a b = ord (f a) (f b) diff --git a/src/core/CCOrd.mli b/src/core/CCOrd.mli index 9311e87f..a8052a93 100644 --- a/src/core/CCOrd.mli +++ b/src/core/CCOrd.mli @@ -15,10 +15,10 @@ val opp : 'a t -> 'a t val equiv : int -> int -> bool (** Returns [true] iff the two comparison results are the same *) -val int_ : int t -val string_ : string t -val bool_ : bool t -val float_ : float t +val int : int t +val string : string t +val bool : bool t +val float : float t (** {2 Lexicographic Combination} *) @@ -31,6 +31,11 @@ val () : int -> ('a t * 'a * 'a) -> int {[CCInt.compare 1 3 (String.compare, "a", "b") (CCBool.compare, true, false)]} + + Same example, using only CCOrd:: + {[CCOrd.(int 1 3 + (string, "a", "b") + (bool, true, false))]} *) val option : 'a t -> 'a option t @@ -41,10 +46,10 @@ val pair : 'a t -> 'b t -> ('a * 'b) t val triple : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t -val list_ : 'a t -> 'a list t +val list : 'a t -> 'a list t (** Lexicographic combination on lists *) -val array_ : 'a t -> 'a array t +val array : 'a t -> 'a array t val map : ('a -> 'b) -> 'b t -> 'a t (** [map f ord] is the comparison function that, given objects [x] and [y],