mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
fix many, many warnings
This commit is contained in:
parent
77ff1ee6a5
commit
bbfbe0f770
14 changed files with 107 additions and 115 deletions
|
|
@ -139,11 +139,15 @@ let rec find_aux f a i =
|
|||
| None -> find_aux f a (i + 1)
|
||||
)
|
||||
|
||||
[@@@ocaml.warning "-32"]
|
||||
|
||||
let find_map f a = find_aux (fun _ -> f) a 0
|
||||
let find = find_map
|
||||
let find_map_i f a = find_aux f a 0
|
||||
let findi = find_map_i
|
||||
|
||||
[@@@ocaml.warning "+32"]
|
||||
|
||||
let find_idx p a =
|
||||
find_aux
|
||||
(fun i x ->
|
||||
|
|
@ -154,58 +158,76 @@ let find_idx p a =
|
|||
a 0
|
||||
|
||||
let max cmp a =
|
||||
if Array.length a = 0 then None
|
||||
else Some (
|
||||
fold
|
||||
(fun acc elt -> if cmp acc elt < 0 then elt else acc)
|
||||
a.(0)
|
||||
a)
|
||||
if Array.length a = 0 then
|
||||
None
|
||||
else
|
||||
Some
|
||||
(fold
|
||||
(fun acc elt ->
|
||||
if cmp acc elt < 0 then
|
||||
elt
|
||||
else
|
||||
acc)
|
||||
a.(0) a)
|
||||
|
||||
let max_exn cmp a =
|
||||
match max cmp a with
|
||||
| None -> invalid_arg "CCArray.max_exn"
|
||||
| Some elt -> elt
|
||||
|
||||
| None -> invalid_arg "CCArray.max_exn"
|
||||
| Some elt -> elt
|
||||
|
||||
let argmax cmp a =
|
||||
if Array.length a = 0 then None
|
||||
else Some (
|
||||
foldi
|
||||
(fun acc i elt -> if cmp a.(acc) elt < 0 then i else acc)
|
||||
0
|
||||
a)
|
||||
if Array.length a = 0 then
|
||||
None
|
||||
else
|
||||
Some
|
||||
(foldi
|
||||
(fun acc i elt ->
|
||||
if cmp a.(acc) elt < 0 then
|
||||
i
|
||||
else
|
||||
acc)
|
||||
0 a)
|
||||
|
||||
let argmax_exn cmp a =
|
||||
match argmax cmp a with
|
||||
| None -> invalid_arg "CCArray.argmax_exn"
|
||||
| Some elt -> elt
|
||||
| None -> invalid_arg "CCArray.argmax_exn"
|
||||
| Some elt -> elt
|
||||
|
||||
let min cmp a =
|
||||
if Array.length a = 0 then None
|
||||
else Some (
|
||||
fold
|
||||
(fun acc elt -> if cmp acc elt > 0 then elt else acc)
|
||||
a.(0)
|
||||
a)
|
||||
if Array.length a = 0 then
|
||||
None
|
||||
else
|
||||
Some
|
||||
(fold
|
||||
(fun acc elt ->
|
||||
if cmp acc elt > 0 then
|
||||
elt
|
||||
else
|
||||
acc)
|
||||
a.(0) a)
|
||||
|
||||
let min_exn cmp a =
|
||||
match min cmp a with
|
||||
| None -> invalid_arg "CCArray.min_exn"
|
||||
| Some elt -> elt
|
||||
|
||||
| None -> invalid_arg "CCArray.min_exn"
|
||||
| Some elt -> elt
|
||||
|
||||
let argmin cmp a =
|
||||
if Array.length a = 0 then None
|
||||
else Some (
|
||||
foldi
|
||||
(fun acc i elt -> if cmp a.(acc) elt > 0 then i else acc)
|
||||
0
|
||||
a)
|
||||
if Array.length a = 0 then
|
||||
None
|
||||
else
|
||||
Some
|
||||
(foldi
|
||||
(fun acc i elt ->
|
||||
if cmp a.(acc) elt > 0 then
|
||||
i
|
||||
else
|
||||
acc)
|
||||
0 a)
|
||||
|
||||
let argmin_exn cmp a =
|
||||
match argmin cmp a with
|
||||
| None -> invalid_arg "CCArray.argmin_exn"
|
||||
| Some elt -> elt
|
||||
| None -> invalid_arg "CCArray.argmin_exn"
|
||||
| Some elt -> elt
|
||||
|
||||
let filter_map f a =
|
||||
let rec aux acc i =
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ end
|
|||
|
||||
include Infix
|
||||
|
||||
[@@@ocaml.warning "-32"]
|
||||
|
||||
let nan = Stdlib.nan
|
||||
let infinity = Stdlib.infinity
|
||||
let neg_infinity = Stdlib.neg_infinity
|
||||
|
|
@ -68,6 +70,8 @@ let equal (a : float) b = a = b
|
|||
let hash : t -> int = Hashtbl.hash
|
||||
let compare (a : float) b = Stdlib.compare a b
|
||||
|
||||
[@@@ocaml.warning "+32"]
|
||||
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,12 @@
|
|||
|
||||
(** {1 Basic Functions} *)
|
||||
|
||||
[@@@ocaml.warning "-32"]
|
||||
|
||||
let opaque_identity x = x
|
||||
|
||||
[@@@ocaml.warning "+32"]
|
||||
|
||||
(* import standard implementations, if any *)
|
||||
|
||||
include Sys
|
||||
|
|
@ -14,13 +18,10 @@ include CCShims_.Stdlib
|
|||
include Fun
|
||||
|
||||
[@@@else_]
|
||||
[@@@ocaml.warning "-32"]
|
||||
|
||||
external id : 'a -> 'a = "%identity"
|
||||
|
||||
let[@inline] flip f x y = f y x
|
||||
let[@inline] const x _ = x
|
||||
let[@inline] negate f x = not (f x)
|
||||
|
||||
let[@inline] protect ~finally f =
|
||||
try
|
||||
let x = f () in
|
||||
|
|
@ -30,6 +31,12 @@ let[@inline] protect ~finally f =
|
|||
finally ();
|
||||
raise e
|
||||
|
||||
[@@@ocaml.warning "+32"]
|
||||
|
||||
let[@inline] flip f x y = f y x
|
||||
let[@inline] const x _ = x
|
||||
let[@inline] negate f x = not (f x)
|
||||
|
||||
[@@@endif]
|
||||
|
||||
let compose f g x = g (f x)
|
||||
|
|
|
|||
|
|
@ -111,10 +111,14 @@ val to_float : t -> float
|
|||
(** [to_float] is the same as [float_of_int]
|
||||
@since 3.0*)
|
||||
|
||||
[@@@ocaml.warning "-32"]
|
||||
|
||||
val of_float : float -> t
|
||||
(** [to_float] is the same as [int_of_float]
|
||||
@since 3.0*)
|
||||
|
||||
[@@@ocaml.warning "+32"]
|
||||
|
||||
val to_string : t -> string
|
||||
(** [to_string x] returns the string representation of the integer [x], in signed decimal.
|
||||
@since 0.13 *)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ open CCShims_
|
|||
|
||||
(* backport new functions from stdlib here *)
|
||||
|
||||
[@@@ocaml.warning "-32"]
|
||||
|
||||
let nth_opt l n =
|
||||
if n < 0 then invalid_arg "nth_opt";
|
||||
let rec aux l n =
|
||||
|
|
@ -46,6 +48,8 @@ let rec assq_opt x = function
|
|||
| (y, v) :: _ when Stdlib.( == ) x y -> Some v
|
||||
| _ :: tail -> assq_opt x tail
|
||||
|
||||
[@@@ocaml.warning "+32"]
|
||||
|
||||
(* end of backport *)
|
||||
|
||||
[@@@ifge 4.8]
|
||||
|
|
|
|||
|
|
@ -33,18 +33,6 @@ val is_empty : _ t -> bool
|
|||
(** [is_empty l] returns [true] iff [l = []].
|
||||
@since 0.11 *)
|
||||
|
||||
val map : ('a -> 'b) -> 'a t -> 'b t
|
||||
(** [map f [a0; a1; …; an]] applies function [f] in turn to [a0; a1; …; an].
|
||||
Safe version of {!List.map}. *)
|
||||
|
||||
val ( >|= ) : 'a t -> ('a -> 'b) -> 'b t
|
||||
(** [l >|= f] is the infix version of [map] with reversed arguments.
|
||||
@since 0.5 *)
|
||||
|
||||
val append : 'a t -> 'a t -> 'a t
|
||||
(** [append l1 l2] returns the list that is the concatenation of [l1] and [l2].
|
||||
Safe version of {!List.append}. *)
|
||||
|
||||
val cons_maybe : 'a option -> 'a t -> 'a t
|
||||
(** [cons_maybe (Some x) l] is [x :: l].
|
||||
[cons_maybe None l] is [l].
|
||||
|
|
@ -55,21 +43,6 @@ val cons' : 'a t -> 'a -> 'a t
|
|||
functions such as {!List.fold_left} or {!Array.fold_left}.
|
||||
@since 3.3 *)
|
||||
|
||||
val ( @ ) : 'a t -> 'a t -> 'a t
|
||||
(** [l1 @ l2] is like [append l1 l2].
|
||||
Concatenate the two lists [l1] and [l2]. *)
|
||||
|
||||
val filter : ('a -> bool) -> 'a t -> 'a t
|
||||
(** [filter p l] returns all the elements of the list [l]
|
||||
that satisfy the predicate [p]. The order of the elements
|
||||
in the input list [l] is preserved.
|
||||
Safe version of {!List.filter}. *)
|
||||
|
||||
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
|
||||
(** [fold_right f [a1; …; an] b] is
|
||||
[f a1 (f a2 ( … (f an b) … ))].
|
||||
Safe version of {!List.fold_right}. *)
|
||||
|
||||
val fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'a
|
||||
(** [fold_while f init l] folds until a stop condition via [('a, `Stop)] is
|
||||
indicated by the accumulator.
|
||||
|
|
@ -408,18 +381,9 @@ val mguard : bool -> unit t
|
|||
]}
|
||||
@since 3.1 *)
|
||||
|
||||
val ( <*> ) : ('a -> 'b) t -> 'a t -> 'b t
|
||||
(** [funs <*> l] is [product (fun f x -> f x) funs l]. *)
|
||||
|
||||
val ( <$> ) : ('a -> 'b) -> 'a t -> 'b t
|
||||
(** [(<$>)] is [map]. *)
|
||||
|
||||
val return : 'a -> 'a t
|
||||
(** [return x] is [x]. *)
|
||||
|
||||
val ( >>= ) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
(** [l >>= f] is [flat_map f l]. *)
|
||||
|
||||
val take : int -> 'a t -> 'a t
|
||||
(** [take n l] takes the [n] first elements of the list [l], drop the rest. *)
|
||||
|
||||
|
|
@ -722,15 +686,6 @@ val range' : int -> int -> int t
|
|||
(** [range' i j] is like {!range} but the second bound [j] is excluded.
|
||||
For instance [range' 0 5 = [0;1;2;3;4]]. *)
|
||||
|
||||
val ( -- ) : int -> int -> int t
|
||||
(** [i -- j] is the list of integers from [i] to [j] included.
|
||||
Infix alias for [range]. *)
|
||||
|
||||
val ( --^ ) : int -> int -> int t
|
||||
(** [i --^ j] is the list of integers from [i] to [j] excluded.
|
||||
Infix alias for [range'].
|
||||
@since 0.17 *)
|
||||
|
||||
val replicate : int -> 'a -> 'a t
|
||||
(** [replicate n x] replicates the given element [x] [n] times. *)
|
||||
|
||||
|
|
|
|||
|
|
@ -178,6 +178,8 @@ module Make (O : Map.OrderedType) = struct
|
|||
(* backport functions from recent stdlib.
|
||||
they will be shadowed by inclusion of [S] if present. *)
|
||||
|
||||
[@@@ocaml.warning "-32"]
|
||||
|
||||
let union f a b =
|
||||
M.merge
|
||||
(fun k v1 v2 ->
|
||||
|
|
@ -230,6 +232,8 @@ module Make (O : Map.OrderedType) = struct
|
|||
| None -> raise Not_found
|
||||
| Some (k, v) -> k, v
|
||||
|
||||
[@@@ocaml.warning "+32"]
|
||||
|
||||
(* === include M.
|
||||
This will shadow some values depending on OCaml's current version
|
||||
=== *)
|
||||
|
|
|
|||
|
|
@ -338,7 +338,6 @@ let parsing what p =
|
|||
}
|
||||
|
||||
let empty = { run = (fun st ~ok ~err:_ -> ok st ()) }
|
||||
let nop = empty
|
||||
let any_char = { run = (fun st ~ok ~err -> consume_ st ~ok ~err) }
|
||||
|
||||
let char c : _ t =
|
||||
|
|
@ -811,8 +810,6 @@ let split_list_at_most ~on_char n : slice list t =
|
|||
in
|
||||
loop [] n
|
||||
|
||||
let split_list ~on_char : _ t = split_list_at_most ~on_char max_int
|
||||
|
||||
let split_2 ~on_char : _ t =
|
||||
split_list_at_most ~on_char 3 >>= function
|
||||
| [ a; b ] -> return (a, b)
|
||||
|
|
@ -948,8 +945,6 @@ let parse_file_exn p file =
|
|||
| Error e -> raise (ParseError e)
|
||||
|
||||
module U = struct
|
||||
let sep_ = sep
|
||||
|
||||
let list ?(start = "[") ?(stop = "]") ?(sep = ";") p =
|
||||
string start *> skip_white
|
||||
*> sep_until
|
||||
|
|
|
|||
|
|
@ -108,11 +108,6 @@ let get_or_failwith = function
|
|||
| Ok x -> x
|
||||
| Error msg -> failwith msg
|
||||
|
||||
let get_lazy default_fn x =
|
||||
match x with
|
||||
| Ok x -> x
|
||||
| Error e -> default_fn e
|
||||
|
||||
let map_or f e ~default =
|
||||
match e with
|
||||
| Ok x -> f x
|
||||
|
|
|
|||
|
|
@ -94,11 +94,6 @@ val get_exn : ('a, _) t -> 'a
|
|||
val get_or : ('a, _) t -> default:'a -> 'a
|
||||
(** [get_or e ~default] returns [x] if [e = Ok x], [default] otherwise. *)
|
||||
|
||||
val get_lazy : ('e -> 'a) -> ('a, 'e) t -> 'a
|
||||
(** [get_lazy f e] returns [x] if [e = Ok x], [f msg] if [e = Error msg].
|
||||
This is similar to {!CCOption.get_lazy}.
|
||||
@since 3.0 *)
|
||||
|
||||
val get_or_failwith : ('a, string) t -> 'a
|
||||
(** [get_or_failwith e] returns [x] if [e = Ok x], fails otherwise.
|
||||
@raise Failure with [msg] if [e = Error msg].
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@ module Make (O : Map.OrderedType) = struct
|
|||
(* backport functions from recent stdlib.
|
||||
they will be shadowed by inclusion of [S] if present. *)
|
||||
|
||||
[@@@ocaml.warning "-32"]
|
||||
|
||||
let find_opt x s = try Some (S.find x s) with Not_found -> None
|
||||
let choose_opt s = try Some (S.choose s) with Not_found -> None
|
||||
let min_elt_opt s = try Some (S.min_elt s) with Not_found -> None
|
||||
|
|
@ -151,17 +153,23 @@ module Make (O : Map.OrderedType) = struct
|
|||
| None -> raise Not_found
|
||||
| Some x -> x
|
||||
|
||||
[@@@ocaml.warning "+32"]
|
||||
|
||||
include S
|
||||
|
||||
(* Use find_last which is linear time on OCaml < 4.05 *)
|
||||
let find_last_map f m =
|
||||
let res = ref None in
|
||||
let _ = find_last_opt
|
||||
(fun x ->
|
||||
match f x with
|
||||
| None -> false
|
||||
| Some y -> res := Some y; true)
|
||||
m in
|
||||
let _ =
|
||||
find_last_opt
|
||||
(fun x ->
|
||||
match f x with
|
||||
| None -> false
|
||||
| Some y ->
|
||||
res := Some y;
|
||||
true)
|
||||
m
|
||||
in
|
||||
!res
|
||||
|
||||
let add_seq seq set =
|
||||
|
|
|
|||
|
|
@ -10,8 +10,17 @@ type uchar = Uchar.t
|
|||
type 'a gen = unit -> 'a option
|
||||
type 'a iter = ('a -> unit) -> unit
|
||||
|
||||
(* compat shim *)
|
||||
|
||||
[@@@ocaml.warning "-32"]
|
||||
|
||||
let equal (a : string) b = Stdlib.( = ) a b
|
||||
let hash : string -> int = Hashtbl.hash
|
||||
|
||||
[@@@ocaml.warning "+32"]
|
||||
|
||||
(* end compat shim *)
|
||||
|
||||
let pp = Format.pp_print_string
|
||||
|
||||
include String
|
||||
|
|
|
|||
|
|
@ -500,15 +500,6 @@ let flat_map f v =
|
|||
iter (fun x -> iter (push v') (f x)) v;
|
||||
v'
|
||||
|
||||
let flat_map_iter f v =
|
||||
let v' = create () in
|
||||
iter
|
||||
(fun x ->
|
||||
let seq = f x in
|
||||
append_iter v' seq)
|
||||
v;
|
||||
v'
|
||||
|
||||
let flat_map_seq f v =
|
||||
let v' = create () in
|
||||
iter
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
(preprocess
|
||||
(action
|
||||
(run %{project_root}/src/core/cpp/cpp.exe %{input-file})))
|
||||
(flags :standard -warn-error -a+8 -w -32-70 -safe-string -strict-sequence
|
||||
-nolabels -open CCMonomorphic)
|
||||
(flags :standard -nolabels -open CCMonomorphic)
|
||||
(libraries seq either containers.monomorphic))
|
||||
|
||||
(ocamllex
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue