summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes3
-rw-r--r--otherlibs/num/big_int.ml2
-rw-r--r--otherlibs/num/big_int.mli2
-rw-r--r--otherlibs/num/num.ml2
-rw-r--r--otherlibs/num/num.mli4
-rw-r--r--stdlib/bytes.ml1
-rw-r--r--stdlib/bytes.mli3
-rw-r--r--stdlib/char.ml1
-rw-r--r--stdlib/char.mli4
-rw-r--r--stdlib/digest.ml1
-rw-r--r--stdlib/digest.mli4
-rw-r--r--stdlib/int32.ml1
-rw-r--r--stdlib/int32.mli4
-rw-r--r--stdlib/int64.ml1
-rw-r--r--stdlib/int64.mli4
-rw-r--r--stdlib/nativeint.ml1
-rw-r--r--stdlib/nativeint.mli4
-rw-r--r--stdlib/string.ml1
-rw-r--r--stdlib/string.mli4
-rw-r--r--testsuite/tests/typing-modules/aliases.ml.reference4
20 files changed, 51 insertions, 0 deletions
diff --git a/Changes b/Changes
index 2a030d365d..69157e5e1b 100644
--- a/Changes
+++ b/Changes
@@ -29,6 +29,9 @@ Runtime system:
(Xavier Leroy)
Standard library:
+* PR#6494: Add equal function in modules
+ Big_int, Bytes, Char, Digest, Int32, Int64, Nativeint, Num and String
+ (Romain Calascibetta)
- PR#6577: improve performance of %L, %l, %n, %S, %C format specifiers
(Alain Frisch)
- PR#6585: fix memory leak in win32unix/createprocess.c
diff --git a/otherlibs/num/big_int.ml b/otherlibs/num/big_int.ml
index 847d158324..36e40f4dd4 100644
--- a/otherlibs/num/big_int.ml
+++ b/otherlibs/num/big_int.ml
@@ -70,6 +70,8 @@ let compare_big_int bi1 bi2 =
compare_nat (bi2.abs_value) 0 (num_digits_big_int bi2)
(bi1.abs_value) 0 (num_digits_big_int bi1)
+let equal bi1 bi2 = compare_big_int bi1 bi2 = 0
+
let eq_big_int bi1 bi2 = compare_big_int bi1 bi2 = 0
and le_big_int bi1 bi2 = compare_big_int bi1 bi2 <= 0
and ge_big_int bi1 bi2 = compare_big_int bi1 bi2 >= 0
diff --git a/otherlibs/num/big_int.mli b/otherlibs/num/big_int.mli
index 738730a79a..09f4514203 100644
--- a/otherlibs/num/big_int.mli
+++ b/otherlibs/num/big_int.mli
@@ -86,6 +86,8 @@ val compare_big_int : big_int -> big_int -> int
(** [compare_big_int a b] returns [0] if [a] and [b] are equal,
[1] if [a] is greater than [b], and [-1] if [a] is smaller
than [b]. *)
+val equal : big_int -> big_int -> bool
+ (** The equal function for big ints. @since 4.03.0 *)
val eq_big_int : big_int -> big_int -> bool
val le_big_int : big_int -> big_int -> bool
val ge_big_int : big_int -> big_int -> bool
diff --git a/otherlibs/num/num.ml b/otherlibs/num/num.ml
index 67499e2674..67cc16c0b6 100644
--- a/otherlibs/num/num.ml
+++ b/otherlibs/num/num.ml
@@ -330,6 +330,8 @@ and le_num num1 num2 = compare_num num1 num2 <= 0
and gt_num num1 num2 = compare_num num1 num2 > 0
and ge_num num1 num2 = compare_num num1 num2 >= 0
+let equal a b = compare_num a b = 0
+
let ( </ ) = lt_num
and ( <=/ ) = le_num
and ( >/ ) = gt_num
diff --git a/otherlibs/num/num.mli b/otherlibs/num/num.mli
index 6425085e63..a43929ef2b 100644
--- a/otherlibs/num/num.mli
+++ b/otherlibs/num/num.mli
@@ -129,6 +129,10 @@ val compare_num : num -> num -> int
(** Return [-1], [0] or [1] if the first argument is less than,
equal to, or greater than the second argument. *)
+val equal : num -> num -> bool
+(** The equal function for nums.
+ @since 4.03.0 *)
+
val max_num : num -> num -> num
(** Return the greater of the two arguments. *)
diff --git a/stdlib/bytes.ml b/stdlib/bytes.ml
index ce6e126db8..4170ad02e5 100644
--- a/stdlib/bytes.ml
+++ b/stdlib/bytes.ml
@@ -260,3 +260,4 @@ let rcontains_from s i c =
type t = bytes
let compare (x: t) (y: t) = Pervasives.compare x y
+external equal : t -> t -> bool = "caml_string_equal"
diff --git a/stdlib/bytes.mli b/stdlib/bytes.mli
index 82b28a28c5..e873463a1f 100644
--- a/stdlib/bytes.mli
+++ b/stdlib/bytes.mli
@@ -255,6 +255,9 @@ val compare: t -> t -> int
this function [compare] allows the module [Bytes] to be passed as
argument to the functors {!Set.Make} and {!Map.Make}. *)
+val equal: t -> t -> bool
+(** The equality function for byte sequences.
+ @since 4.03.0 *)
(** {4 Unsafe conversions (for advanced users)}
diff --git a/stdlib/char.ml b/stdlib/char.ml
index 15c4635429..1ba5bf6ff9 100644
--- a/stdlib/char.ml
+++ b/stdlib/char.ml
@@ -65,3 +65,4 @@ let uppercase c =
type t = char
let compare c1 c2 = code c1 - code c2
+let equal (c1: t) (c2: t) = compare c1 c2 = 0
diff --git a/stdlib/char.mli b/stdlib/char.mli
index d1baa64d3f..0ff4efb082 100644
--- a/stdlib/char.mli
+++ b/stdlib/char.mli
@@ -41,6 +41,10 @@ val compare: t -> t -> int
allows the module [Char] to be passed as argument to the functors
{!Set.Make} and {!Map.Make}. *)
+val equal: t -> t -> bool
+(** The equal function for chars.
+ @since 4.03.0 *)
+
(**/**)
(* The following is for system use only. Do not call directly. *)
diff --git a/stdlib/digest.ml b/stdlib/digest.ml
index 14cb4ebd90..4261564ffe 100644
--- a/stdlib/digest.ml
+++ b/stdlib/digest.ml
@@ -16,6 +16,7 @@
type t = string
let compare = String.compare
+let equal = String.equal
external unsafe_string: string -> int -> int -> t = "caml_md5_string"
external channel: in_channel -> int -> t = "caml_md5_chan"
diff --git a/stdlib/digest.mli b/stdlib/digest.mli
index 9227cd7de8..29e5b3973e 100644
--- a/stdlib/digest.mli
+++ b/stdlib/digest.mli
@@ -33,6 +33,10 @@ val compare : t -> t -> int
argument to the functors {!Set.Make} and {!Map.Make}.
@since 4.00.0 *)
+val equal : t -> t -> bool
+(** The equal function for 16-character digest.
+ @since 4.03.0 *)
+
val string : string -> t
(** Return the digest of the given string. *)
diff --git a/stdlib/int32.ml b/stdlib/int32.ml
index e8e55ddc84..63c99e3d42 100644
--- a/stdlib/int32.ml
+++ b/stdlib/int32.ml
@@ -50,3 +50,4 @@ external of_string : string -> int32 = "caml_int32_of_string"
type t = int32
let compare (x: t) (y: t) = Pervasives.compare x y
+let equal (x: t) (y: t) = compare x y = 0
diff --git a/stdlib/int32.mli b/stdlib/int32.mli
index fcd300a2d5..4a29e6c0f2 100644
--- a/stdlib/int32.mli
+++ b/stdlib/int32.mli
@@ -153,6 +153,10 @@ val compare: t -> t -> int
allows the module [Int32] to be passed as argument to the functors
{!Set.Make} and {!Map.Make}. *)
+val equal: t -> t -> bool
+(** The equal function for int32s.
+ @since 4.03.0 *)
+
(**/**)
(** {6 Deprecated functions} *)
diff --git a/stdlib/int64.ml b/stdlib/int64.ml
index aa4add5f1b..274a9868d9 100644
--- a/stdlib/int64.ml
+++ b/stdlib/int64.ml
@@ -55,3 +55,4 @@ external float_of_bits : int64 -> float = "caml_int64_float_of_bits"
type t = int64
let compare (x: t) (y: t) = Pervasives.compare x y
+let equal (x: t) (y: t) = compare x y = 0
diff --git a/stdlib/int64.mli b/stdlib/int64.mli
index 09b476f15a..edd600c690 100644
--- a/stdlib/int64.mli
+++ b/stdlib/int64.mli
@@ -175,6 +175,10 @@ val compare: t -> t -> int
allows the module [Int64] to be passed as argument to the functors
{!Set.Make} and {!Map.Make}. *)
+val equal: t -> t -> bool
+(** The equal function for int64s.
+ @since 4.03.0 *)
+
(**/**)
(** {6 Deprecated functions} *)
diff --git a/stdlib/nativeint.ml b/stdlib/nativeint.ml
index 94c4b94901..7412bca04e 100644
--- a/stdlib/nativeint.ml
+++ b/stdlib/nativeint.ml
@@ -51,3 +51,4 @@ external of_string: string -> nativeint = "caml_nativeint_of_string"
type t = nativeint
let compare (x: t) (y: t) = Pervasives.compare x y
+let equal (x: t) (y: t) = compare x y = 0
diff --git a/stdlib/nativeint.mli b/stdlib/nativeint.mli
index 3dce1b6c49..ffa57030cd 100644
--- a/stdlib/nativeint.mli
+++ b/stdlib/nativeint.mli
@@ -171,6 +171,10 @@ val compare: t -> t -> int
allows the module [Nativeint] to be passed as argument to the functors
{!Set.Make} and {!Map.Make}. *)
+val equal: t -> t -> bool
+(** The equal function for natives ints.
+ @since 4.03.0 *)
+
(**/**)
(** {6 Deprecated functions} *)
diff --git a/stdlib/string.ml b/stdlib/string.ml
index 93880af268..8b2dde65d6 100644
--- a/stdlib/string.ml
+++ b/stdlib/string.ml
@@ -124,3 +124,4 @@ let uncapitalize s =
type t = string
let compare (x: t) (y: t) = Pervasives.compare x y
+external equal : string -> string -> bool = "caml_string_equal"
diff --git a/stdlib/string.mli b/stdlib/string.mli
index 56065bbfbd..e063e6bdba 100644
--- a/stdlib/string.mli
+++ b/stdlib/string.mli
@@ -239,6 +239,10 @@ val compare: t -> t -> int
allows the module [String] to be passed as argument to the functors
{!Set.Make} and {!Map.Make}. *)
+val equal: t -> t -> bool
+(** The equal function for strings.
+ @since 4.03.0 *)
+
(**/**)
(* The following is for system use only. Do not call directly. *)
diff --git a/testsuite/tests/typing-modules/aliases.ml.reference b/testsuite/tests/typing-modules/aliases.ml.reference
index db35fa5e86..6469844b49 100644
--- a/testsuite/tests/typing-modules/aliases.ml.reference
+++ b/testsuite/tests/typing-modules/aliases.ml.reference
@@ -10,6 +10,7 @@
val uppercase : char -> char
type t = char
val compare : t -> t -> int
+ val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
# - : char = 'B'
@@ -22,6 +23,7 @@
val uppercase : char -> char
type t = char
val compare : t -> t -> int
+ val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
# - : char = 'B'
@@ -37,6 +39,7 @@
val uppercase : char -> char
type t = char
val compare : t -> t -> int
+ val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
# module C4 :
@@ -48,6 +51,7 @@
val uppercase : char -> char
type t = char
val compare : t -> t -> int
+ val equal : t -> t -> bool
external unsafe_chr : int -> char = "%identity"
end
# - : char = 'B'