Skip to content

Commit bcfa092

Browse files
authored
Merge pull request #436 from c-cube/408-cleanup
post 4.08 cleanup, removing a lot of functions that are now always present in the stdlib.
2 parents 5461dcc + 35803e5 commit bcfa092

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+487
-1130
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
## main
3+
- breaking: CCListLabel.compare and CCListLabel.equal takes the function on the elements as named arguments
4+
- breaking: CCListLabel.init now takes the length as a named arguments to follow the Stdlib
5+
- breaking: change the semantic of CCFloat.{min,max} with respect to NaN to follow the Stdlib
6+
- breaking: change the semantic of CCInt.rem with respect to negative number to follow the Stdlib
7+
- breaking: change the order of argument of CCMap.add_seq to align with the stdlib.
28

39
## 3.17
410

@@ -60,6 +66,7 @@
6066

6167
## 3.13
6268

69+
- breaking: bump minimum version of OCaml to 4.08
6370
- breaking: delete containers-thread (which was deprecated)
6471
- breaking: pp: modify `Ext.t` so it takes surrounding value
6572
- breaking: remove CCShims

src/core/CCArray.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,6 @@ let pp_i ?(pp_start = fun _ () -> ()) ?(pp_stop = fun _ () -> ())
455455
let to_string ?(sep = ", ") item_to_string a =
456456
Array.to_list a |> List.map item_to_string |> String.concat sep
457457
458-
let to_seq a =
459-
let rec aux i () =
460-
if i >= length a then
461-
Seq.Nil
462-
else
463-
Seq.Cons (a.(i), aux (i + 1))
464-
in
465-
aux 0
466-
467458
let to_iter a k = iter k a
468459
469460
let to_gen a =

src/core/CCArray.mli

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,6 @@ val to_iter : 'a t -> 'a iter
240240
in modification of the iterator.
241241
@since 2.8 *)
242242

243-
val to_seq : 'a t -> 'a Seq.t
244-
(** [to_seq a] returns a [Seq.t] of the elements of an array [a].
245-
The input array [a] is shared with the sequence and modification of it will result
246-
in modification of the sequence.
247-
Renamed from [to_std_seq] since 3.0.
248-
@since 3.0
249-
*)
250-
251243
val to_gen : 'a t -> 'a gen
252244
(** [to_gen a] returns a [gen] of the elements of an array [a]. *)
253245

src/core/CCArrayLabels.mli

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,6 @@ val fold2 : f:('acc -> 'a -> 'b -> 'acc) -> init:'acc -> 'a t -> 'b t -> 'acc
219219
@raise Invalid_argument if [a] and [b] have distinct lengths.
220220
@since 0.20 *)
221221

222-
val iter2 : f:('a -> 'b -> unit) -> 'a t -> 'b t -> unit
223-
(** [iter2 ~f a b] iterates on the two arrays [a] and [b] stepwise.
224-
It is equivalent to [f a0 b0; …; f a.(length a - 1) b.(length b - 1); ()].
225-
226-
@raise Invalid_argument if [a] and [b] have distinct lengths.
227-
@since 0.20 *)
228-
229222
val shuffle : 'a t -> unit
230223
(** [shuffle a] randomly shuffles the array [a], in place. *)
231224

@@ -248,14 +241,6 @@ val to_iter : 'a t -> 'a iter
248241
in modification of the iterator.
249242
@since 2.8 *)
250243

251-
val to_seq : 'a t -> 'a Seq.t
252-
(** [to_seq a] returns a [Seq.t] of the elements of an array [a].
253-
The input array [a] is shared with the sequence and modification of it will result
254-
in modification of the sequence.
255-
Renamed from [to_std_seq] since 3.0.
256-
@since 3.0
257-
*)
258-
259244
val to_gen : 'a t -> 'a gen
260245
(** [to_gen a] returns a [gen] of the elements of an array [a]. *)
261246

@@ -286,14 +271,6 @@ val pp_i :
286271
By defaults [pp_start] and [pp_stop] does nothing and [pp_sep] defaults to
287272
(fun out -> Format.fprintf out ",@ "). *)
288273

289-
val map2 : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
290-
(** [map2 ~f a b] applies function [f] to all elements of [a] and [b],
291-
and builds an array with the results returned by [f]:
292-
[[| f a.(0) b.(0); …; f a.(length a - 1) b.(length b - 1)|]].
293-
294-
@raise Invalid_argument if [a] and [b] have distinct lengths.
295-
@since 0.20 *)
296-
297274
val rev : 'a t -> 'a t
298275
(** [rev a] copies the array [a] and reverses it in place.
299276
@since 0.20 *)
@@ -308,7 +285,7 @@ val filter_map : f:('a -> 'b option) -> 'a t -> 'b t
308285
element of [a] is discarded. *)
309286

310287
val monoid_product : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
311-
(** [monoid_product ~f a b] passes all combinaisons of tuples from the two arrays [a] and [b]
288+
(** [monoid_product ~f a b] passes all combinaisons of tuples from the two arrays [a] and [b]
312289
to the function [f].
313290
@since 2.8 *)
314291

src/core/CCBool.ml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
(* This file is free software, part of containers. See file "license" for more details. *)
22

3-
type t = bool
4-
5-
let equal (a : bool) b = Stdlib.( = ) a b
6-
let compare (a : bool) b = Stdlib.compare a b
3+
include Bool
74

85
let if_then f x =
96
if x then
@@ -17,12 +14,6 @@ let if_then_else f g x =
1714
else
1815
g ()
1916

20-
let to_int (x : bool) : int =
21-
if x then
22-
1
23-
else
24-
0
25-
2617
let of_int x : t = x <> 0
2718

2819
type 'a printer = Format.formatter -> 'a -> unit

src/core/CCBool.mli

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
(** Basic Bool functions *)
44

5-
type t = bool
6-
7-
val compare : t -> t -> int
8-
(** [compare b1 b2] is the total ordering on booleans [b1] and [b2], similar to {!Stdlib.compare}. *)
9-
10-
val equal : t -> t -> bool
11-
(** [equal b1 b2] is [true] if [b1] and [b2] are the same. *)
5+
include module type of Bool
6+
(** @inline *)
127

138
val if_then : (unit -> 'a) -> t -> 'a option
149
(** [if_then f x] is [Some (f ())] if [x] is true and None otherwise.
@@ -18,10 +13,6 @@ val if_then_else : (unit -> 'a) -> (unit -> 'a) -> t -> 'a
1813
(** [if_then_else f g x] is [f ()] if [x] is true and [g ()] otherwise.
1914
@since 3.13 *)
2015

21-
val to_int : t -> int
22-
(** [to_int true = 1], [to_int false = 0].
23-
@since 2.7 *)
24-
2516
val of_int : int -> t
2617
(** [of_int i] is the same as [i <> 0]
2718
@since 2.7 *)

src/core/CCChar.mli

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ include module type of struct
99
include Char
1010
end
1111

12-
val compare : t -> t -> int
13-
(** The comparison function for characters, with the same specification as
14-
{!Stdlib.compare}. Along with the type [t], this function [compare]
15-
allows the module [Char] to be passed as argument to the functors
16-
{!Set.Make} and {!Map.Make}. *)
17-
1812
val of_int_exn : int -> t
1913
(** Alias to {!Char.chr}.
2014
Return the character with the given ASCII code.

src/core/CCEither.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ type 'a equal = 'a -> 'a -> bool
55
type 'a ord = 'a -> 'a -> int
66
type 'a printer = Format.formatter -> 'a -> unit
77

8+
[@@@ifge 4.12]
9+
10+
include Either
11+
12+
[@@@else_]
13+
814
(** {2 Basics} *)
915

1016
type ('a, 'b) t = ('a, 'b) Either.t =
@@ -62,6 +68,8 @@ let compare ~left ~right e1 e2 =
6268
| Left l1, Left l2 -> left l1 l2
6369
| Right r1, Right r2 -> right r1 r2
6470

71+
[@@@endif]
72+
6573
(** {2 IO} *)
6674

6775
let pp ~left ~right fmt = function

src/core/CCEither.mli

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ type 'a equal = 'a -> 'a -> bool
1313
type 'a ord = 'a -> 'a -> int
1414
type 'a printer = Format.formatter -> 'a -> unit
1515

16+
[@@@ifge 4.12]
17+
18+
include module type of Either
19+
(** @inline *)
20+
21+
[@@@else_]
22+
1623
(** {2 Basics} *)
1724

1825
type ('a, 'b) t = ('a, 'b) Either.t =
@@ -70,6 +77,8 @@ val compare :
7077
('a, 'b) t ->
7178
int
7279

80+
[@@@endif]
81+
7382
(** {2 IO} *)
7483

7584
val pp : left:'a printer -> right:'b printer -> ('a, 'b) t printer

src/core/CCFloat.ml

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
(* This file is free software, part of containers. See file "license" for more details. *)
22

3-
type t = float
4-
5-
type fpclass = Stdlib.fpclass =
6-
| FP_normal
7-
| FP_subnormal
8-
| FP_zero
9-
| FP_infinite
10-
| FP_nan
3+
include Float
114

125
module Infix = struct
136
let ( = ) : t -> t -> bool = Stdlib.( = )
@@ -27,47 +20,11 @@ include Infix
2720

2821
[@@@ocaml.warning "-32"]
2922

30-
let nan = Stdlib.nan
31-
let infinity = Stdlib.infinity
32-
let neg_infinity = Stdlib.neg_infinity
3323
let max_value = infinity
3424
let min_value = neg_infinity
3525
let max_finite_value = Stdlib.max_float
36-
let epsilon = Stdlib.epsilon_float
37-
let pi = 0x1.921fb54442d18p+1
38-
let is_nan x = Stdlib.(classify_float x = Stdlib.FP_nan)
39-
let add = ( +. )
40-
let sub = ( -. )
41-
let mul = ( *. )
42-
let div = ( /. )
43-
let neg = ( ~-. )
44-
let abs = Stdlib.abs_float
4526
let scale = ( *. )
4627

47-
let min (x : t) y =
48-
match Stdlib.classify_float x, Stdlib.classify_float y with
49-
| FP_nan, _ -> y
50-
| _, FP_nan -> x
51-
| _ ->
52-
if x < y then
53-
x
54-
else
55-
y
56-
57-
let max (x : t) y =
58-
match Stdlib.classify_float x, Stdlib.classify_float y with
59-
| FP_nan, _ -> y
60-
| _, FP_nan -> x
61-
| _ ->
62-
if x > y then
63-
x
64-
else
65-
y
66-
67-
let equal (a : float) b = a = b
68-
let hash : t -> int = Hashtbl.hash
69-
let compare (a : float) b = Stdlib.compare a b
70-
7128
[@@@ocaml.warning "+32"]
7229

7330
type 'a printer = Format.formatter -> 'a -> unit
@@ -91,22 +48,7 @@ let sign_exn (a : float) =
9148
else
9249
compare a 0.
9350

94-
let round x =
95-
let low = floor x in
96-
let high = ceil x in
97-
if x -. low > high -. x then
98-
high
99-
else
100-
low
101-
102-
let to_int (a : float) = Stdlib.int_of_float a
103-
let of_int (a : int) = Stdlib.float_of_int a
104-
let to_string (a : float) = Stdlib.string_of_float a
10551
let of_string_exn (a : string) = Stdlib.float_of_string a
106-
107-
let of_string_opt (a : string) =
108-
try Some (Stdlib.float_of_string a) with Failure _ -> None
109-
11052
let random n st = Random.State.float st n
11153
let random_small = random 100.0
11254
let random_range i j st = i +. random (j -. i) st

0 commit comments

Comments
 (0)