wip(3.0): remove deprecated functions, in particular sequence

This commit is contained in:
Simon Cruanes 2020-04-24 20:16:53 -04:00
parent 46e40c9165
commit a767e4618d
56 changed files with 945 additions and 716 deletions

3
.gitignore vendored
View file

@ -4,10 +4,11 @@ _build
*.native
*.byte
.session
TAGS
*.docdir
setup.*
*.html
.merlin
*.install
.ignore
_opam
*.exe

View file

@ -20,6 +20,7 @@ BENCH_TARGETS=run_benchs.exe run_bench_hash.exe
benchs:
dune build $(PROMOTE) $(addprefix benchs/, $(BENCH_TARGETS))
@for i in $(BENCH_TARGETS) ; do ln -sf _build/default/benchs/$$i ; done
examples:
dune build examples/id_sexp.exe

View file

@ -1,9 +1,8 @@
(executables
(names run_benchs run_bench_hash run_objsize)
(libraries containers containers.data containers.iter
containers.thread benchmark gen iter qcheck oseq
(libraries containers containers-data
containers-thread benchmark gen iter qcheck oseq
batteries base sek)
(flags :standard -warn-error -3 -safe-string -color always -open CCShims_)
(ocamlopt_flags :standard -O3 -color always
-unbox-closures -unbox-closures-factor 20)
)
-unbox-closures -unbox-closures-factor 20))

View file

@ -1,9 +1,8 @@
(executable
(name id_sexp)
(libraries containers.sexp)
(libraries containers)
(modules id_sexp)
(flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always)
(flags :standard -warn-error -a+8 -safe-string -color always)
(ocamlopt_flags :standard -O3 -color always
-unbox-closures -unbox-closures-factor 20)
)
-unbox-closures -unbox-closures-factor 20))

View file

@ -14,11 +14,12 @@
(modes native)
(modules run_qtest)
; disable some warnings in qtests
(flags :standard -warn-error -a -w -3-33-35-27-39 -nolabels)
(libraries iter gen qcheck containers containers.unix unix uutf))
(flags :standard -warn-error -a -w -3-33-35-27-39-50 -nolabels)
(libraries iter gen qcheck containers containers.unix unix uutf threads))
(alias
(name runtest)
(locks ctest)
(package containers)
(action (run ./run_qtest.exe)))
@ -32,12 +33,13 @@
(modes native)
(modules run_qtest_data)
; disable some warnings in qtests
(flags :standard -warn-error -a -w -3-33-35-27-39)
(flags :standard -warn-error -a -w -3-33-35-27-39-50)
(libraries iter gen qcheck containers containers-data))
(alias
(name runtest)
(package containers-data)
(locks ctest)
(action (run ./run_qtest_data.exe)))
(rule
@ -50,10 +52,11 @@
(modes native)
(modules run_qtest_thread)
; disable some warnings in qtests
(flags :standard -warn-error -a -w -3-33-35-27-39)
(flags :standard -warn-error -a -w -3-33-35-27-39-50)
(libraries qcheck containers containers-thread iter threads))
(alias
(name runtest)
(locks ctest)
(package containers-thread)
(action (run ./run_qtest_thread.exe)))

View file

@ -18,7 +18,7 @@ let do_not_test file =
assert (not (is_suffix ~sub:"make.ml" file));
str_sub ~sub:"Labels.ml" file ||
is_suffix ~sub:"containers.ml" file ||
is_suffix ~sub:"containers_top.ml" file ||
is_suffix ~sub:"_top.ml" file ||
is_suffix ~sub:"mkflags.ml" file ||
is_suffix ~sub:"mkshims.ml" file ||
is_suffix ~sub:"unlabel.ml" file ||

View file

@ -3,8 +3,6 @@
(** {1 Array utils} *)
type 'a iter = ('a -> unit) -> unit
type 'a sequence = ('a -> unit) -> unit
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
type 'a gen = unit -> 'a option
type 'a equal = 'a -> 'a -> bool
type 'a ord = 'a -> 'a -> int
@ -549,7 +547,6 @@ let to_std_seq a =
*)
let to_iter a k = iter k a
let to_seq = to_iter
let to_gen a =
let k = ref 0 in
@ -561,8 +558,6 @@ let to_gen a =
Some x
) else None
let to_klist a = _to_klist a 0 (Array.length a)
(** {2 Generic Functions} *)
module type MONO_ARRAY = sig

View file

@ -3,15 +3,10 @@
(** {1 Array utils} *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
type 'a gen = unit -> 'a option
type 'a equal = 'a -> 'a -> bool
type 'a ord = 'a -> 'a -> int
@ -143,27 +138,12 @@ val find_map : ('a -> 'b option) -> 'a t -> 'b option
@since 1.3, but only
@since 2.1 with labels *)
val find : ('a -> 'b option) -> 'a t -> 'b option
(** [find f a] is an alias to {!find_map}.
@deprecated since 1.3, use {!find_map} instead.
The version with labels is
@deprecated since 2.1, use {!find_map} instead. *)
[@@ocaml.deprecated "use find_map instead"]
val find_map_i : (int -> 'a -> 'b option) -> 'a t -> 'b option
(** [find_map_i f a] is like {!find_map}, but the index of the element is also passed
to the predicate function [f].
@since 1.3, but only
@since 2.1 with labels *)
val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option
(** [findi f a] is an alias to {!find_map_i}.
@since 0.3.4
@deprecated since 1.3, use {!find_map_i} instead.
The version with labels is
@deprecated since 2.1, use {!find_map_i} instead. *)
[@@ocaml.deprecated "use find_map_i instead"]
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option
(** [find_idx f a] returns [Some (i,x)] where [x] is the [i]-th element of [a],
and [f x] holds. Otherwise returns [None].
@ -253,19 +233,9 @@ val to_std_seq : 'a t -> 'a Seq.t
@since 2.8
*)
val to_seq : 'a t -> 'a sequence
(** Same as {!to_iter}.
@deprecated use {!to_iter} instead *)
[@@ocaml.deprecated "use to_iter or to_std_seq"]
val to_gen : 'a t -> 'a gen
(** [to_gen a] returns a [gen] of the elements of an array [a]. *)
val to_klist : 'a t -> 'a klist
(** [to_klist] returns a [klist] of the elements of an array [a].
@deprecated use {!to_std_seq} *)
[@@ocaml.deprecated "use to_std_seq"]
(** {2 IO} *)
val pp: ?sep:string -> 'a printer -> 'a t printer

View file

@ -2,16 +2,10 @@
(** {1 Array utils} *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
type 'a gen = unit -> 'a option
type 'a equal = 'a -> 'a -> bool
type 'a ord = 'a -> 'a -> int
@ -143,27 +137,12 @@ val find_map : f:('a -> 'b option) -> 'a t -> 'b option
@since 1.3, but only
@since 2.1 with labels *)
val find : f:('a -> 'b option) -> 'a t -> 'b option
(** [find ~f a] is an alias to {!find_map}.
@deprecated since 1.3, use {!find_map} instead.
The version with labels is
@deprecated since 2.1, use {!find_map} instead. *)
[@@ocaml.deprecated "use find_map instead"]
val find_map_i : f:(int -> 'a -> 'b option) -> 'a t -> 'b option
(** [find_map_i ~f a] is like {!find_map}, but the index of the element is also passed
to the predicate function [~f].
@since 1.3, but only
@since 2.1 with labels *)
val findi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option
(** [findi ~f a] is an alias to {!find_map_i}.
@since 0.3.4
@deprecated since 1.3, use {!find_map_i} instead.
The version with labels is
@deprecated since 2.1, use {!find_map_i} instead. *)
[@@ocaml.deprecated "use find_map_i instead"]
val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) option
(** [find_idx ~f a] returns [Some (i,x)] where [x] is the [i]-th element of [a],
and [~f x] holds. Otherwise returns [None].
@ -260,19 +239,9 @@ val to_std_seq : 'a t -> 'a Seq.t
@since 2.8
*)
val to_seq : 'a t -> 'a sequence
(** Same as {!to_iter}.
@deprecated use {!to_iter} instead *)
[@@ocaml.deprecated "use to_iter or to_std_seq"]
val to_gen : 'a t -> 'a gen
(** [to_gen a] returns a [gen] of the elements of an array [a]. *)
val to_klist : 'a t -> 'a klist
(** [to_klist] returns a [klist] of the elements of an array [a].
@deprecated use {!to_std_seq} *)
[@@ocaml.deprecated "use to_std_seq"]
(** {2 IO} *)
val pp: ?sep:string -> 'a printer -> 'a t printer

View file

@ -25,8 +25,6 @@ let of_int x : t = x<>0
true (of_int min_int)
*)
let negate = not
type 'a printer = Format.formatter -> 'a -> unit
let pp = Format.pp_print_bool

View file

@ -18,11 +18,6 @@ val of_int : int -> t
(** [of_int i] is the same as [i <> 0]
@since 2.7 *)
val negate : t -> t
(** Negation on booleans (functional version of [not]).
@deprecated since 1.3, simply use {!not} instead. *)
[@@ocaml.deprecated "use `not` instead"]
type 'a printer = Format.formatter -> 'a -> unit
val pp : t printer

View file

@ -111,7 +111,6 @@ let of_int (a:int) = Stdlib.float_of_int a
let to_string (a:float) = Stdlib.string_of_float a
let of_string_exn (a:string) = Stdlib.float_of_string a
let of_string (a:string) = Stdlib.float_of_string a
let of_string_opt (a:string) =
try Some (Stdlib.float_of_string a)
with Failure _ -> None

View file

@ -103,12 +103,6 @@ val of_string_exn : string -> t
@raise Failure in case of failure.
@since 1.2 *)
val of_string : string -> t
(** Alias to {!float_of_string}.
@deprecated since 1.2, use {!of_string_exn} instead.
@raise Failure in case of failure. *)
[@@ocaml.deprecated "use of_string_exn instead"]
val of_string_opt : string -> t option
(** @since NEXT_RELEASE *)

View file

@ -4,7 +4,6 @@
(** {1 Extension to the standard Hashtbl} *)
type 'a iter = ('a -> unit) -> unit
type 'a sequence = ('a -> unit) -> unit
type 'a eq = 'a -> 'a -> bool
type 'a hash = 'a -> int
type 'a printer = Format.formatter -> 'a -> unit
@ -90,12 +89,6 @@ module Poly = struct
add_std_seq_count tbl i;
tbl
let to_seq = to_iter
let add_seq = add_iter
let of_seq = of_iter
let add_seq_count = add_iter_count
let of_seq_count = of_iter_count
let to_list tbl =
Hashtbl.fold
(fun k v l -> (k,v) :: l)
@ -213,11 +206,6 @@ module type S = sig
(** Iterate on bindings in the table.
@since 2.8 *)
val to_seq : 'a t -> (key * 'a) sequence
(** Iterate on values in the table.
@deprecated use {!to_iter} instead *)
[@@ocaml.deprecated "use to_iter"]
val add_iter : 'a t -> (key * 'a) iter -> unit
(** Add the corresponding pairs to the table, using {!Hashtbl.add}.
@since 2.8 *)
@ -226,12 +214,6 @@ module type S = sig
(** Add the corresponding pairs to the table, using {!Hashtbl.add}.
@since 2.8 *)
val add_seq : 'a t -> (key * 'a) sequence -> unit
(** Add the corresponding pairs to the table, using {!Hashtbl.add}.
@since 0.16
@deprecated use {!add_iter} or {!add_std_seq} *)
[@@ocaml.deprecated "use add_iter or add_std_seq"]
val of_iter : (key * 'a) iter -> 'a t
(** From the given bindings, added in order.
@since 2.8 *)
@ -240,11 +222,6 @@ module type S = sig
(** From the given bindings, added in order.
@since 2.8 *)
val of_seq : (key * 'a) sequence -> 'a t
(** From the given bindings, added in order.
@deprecated use {!of_iter} or {!of_std_seq} *)
[@@ocaml.deprecated "use of_iter or of_std_seq"]
val add_iter_count : int t -> key iter -> unit
(** [add_iter_count tbl i] increments the count of each element of [i]
by calling {!incr}. This is useful for counting how many times each
@ -257,14 +234,6 @@ module type S = sig
element of [seq] occurs.
@since 2.8 *)
val add_seq_count : int t -> key sequence -> unit
(** [add_seq_count tbl seq] increments the count of each element of [seq]
by calling {!incr}. This is useful for counting how many times each
element of [seq] occurs.
@since 0.16
@deprecated use {!add_iter_count} or {!add_std_seq_count} *)
[@@ocaml.deprecated "use add_iter_count or add_std_seq_count"]
val of_iter_count : key iter -> int t
(** Like {!add_seq_count}, but allocates a new table and returns it.
@since 2.8 *)
@ -273,12 +242,6 @@ module type S = sig
(** Like {!add_seq_count}, but allocates a new table and returns it.
@since 2.8 *)
val of_seq_count : key sequence -> int t
(** Like {!add_seq_count}, but allocates a new table and returns it.
@since 0.16
@deprecated use {!of_iter_count} or {!of_std_seq_count} *)
[@@ocaml.deprecated "use add_iter_count or add_std_seq_count"]
val to_list : 'a t -> (key * 'a) list
(** List of bindings (order unspecified). *)
@ -420,12 +383,6 @@ module Make(X : Hashtbl.HashedType)
add_std_seq_count tbl i;
tbl
let to_seq = to_iter
let add_seq = add_iter
let of_seq = of_iter
let add_seq_count = add_iter_count
let of_seq_count = of_iter_count
let to_list tbl =
fold
(fun k v l -> (k,v) :: l)

View file

@ -5,11 +5,6 @@
@since 0.4 *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
@ -66,11 +61,6 @@ module Poly : sig
(** Iterate on bindings in the table.
@since 2.8 *)
val to_seq : ('a,'b) Hashtbl.t -> ('a * 'b) sequence
(** Iterate on bindings in the table.
@deprecated use {!to_iter} instead *)
[@@ocaml.deprecated "use to_iter"]
val add_list : ('a, 'b list) Hashtbl.t -> 'a -> 'b -> unit
(** [add_list tbl x y] adds [y] to the list [x] is bound to. If [x] is
not bound, it becomes bound to [y].
@ -84,12 +74,6 @@ module Poly : sig
(** Add the corresponding pairs to the table, using {!Hashtbl.add}.
@since 2.8 *)
val add_seq : ('a,'b) Hashtbl.t -> ('a * 'b) sequence -> unit
(** Add the corresponding pairs to the table, using {!Hashtbl.add}.
@since 0.16
@deprecated use {!add_iter} or {!add_std_seq} *)
[@@ocaml.deprecated "use add_iter or add_std_seq"]
val of_iter : ('a * 'b) iter -> ('a,'b) Hashtbl.t
(** From the given bindings, added in order.
@since 2.8 *)
@ -98,11 +82,6 @@ module Poly : sig
(** From the given bindings, added in order.
@since 2.8 *)
val of_seq : ('a * 'b) sequence -> ('a,'b) Hashtbl.t
(** From the given bindings, added in order.
@deprecated use {!of_iter} or {!of_std_seq} *)
[@@ocaml.deprecated "use of_iter or of_std_seq"]
val add_iter_count : ('a, int) Hashtbl.t -> 'a iter -> unit
(** [add_iter_count tbl i] increments the count of each element of [i]
by calling {!incr}. This is useful for counting how many times each
@ -115,14 +94,6 @@ module Poly : sig
element of [seq] occurs.
@since 2.8 *)
val add_seq_count : ('a, int) Hashtbl.t -> 'a sequence -> unit
(** [add_seq_count tbl seq] increments the count of each element of [seq]
by calling {!incr}. This is useful for counting how many times each
element of [seq] occurs.
@since 0.16
@deprecated use {!add_iter_count} or {!add_std_seq_count} *)
[@@ocaml.deprecated "use add_iter_count or add_std_seq_count"]
val of_iter_count : 'a iter -> ('a, int) Hashtbl.t
(** Like {!add_seq_count}, but allocates a new table and returns it.
@since 2.8 *)
@ -131,12 +102,6 @@ module Poly : sig
(** Like {!add_seq_count}, but allocates a new table and returns it.
@since 2.8 *)
val of_seq_count : 'a sequence -> ('a, int) Hashtbl.t
(** Like {!add_seq_count}, but allocates a new table and returns it.
@since 0.16
@deprecated use {!of_iter_count} or {!of_std_seq_count} *)
[@@ocaml.deprecated "use add_iter_count or add_std_seq_count"]
val to_list : ('a,'b) Hashtbl.t -> ('a * 'b) list
(** List of bindings (order unspecified). *)
@ -222,11 +187,6 @@ module type S = sig
(** Iterate on bindings in the table.
@since 2.8 *)
val to_seq : 'a t -> (key * 'a) sequence
(** Iterate on values in the table.
@deprecated use {!to_iter} instead *)
[@@ocaml.deprecated "use to_iter"]
val add_iter : 'a t -> (key * 'a) iter -> unit
(** Add the corresponding pairs to the table, using {!Hashtbl.add}.
@since 2.8 *)
@ -235,12 +195,6 @@ module type S = sig
(** Add the corresponding pairs to the table, using {!Hashtbl.add}.
@since 2.8 *)
val add_seq : 'a t -> (key * 'a) sequence -> unit
(** Add the corresponding pairs to the table, using {!Hashtbl.add}.
@since 0.16
@deprecated use {!add_iter} or {!add_std_seq} *)
[@@ocaml.deprecated "use add_iter or add_std_seq"]
val of_iter : (key * 'a) iter -> 'a t
(** From the given bindings, added in order.
@since 2.8 *)
@ -249,11 +203,6 @@ module type S = sig
(** From the given bindings, added in order.
@since 2.8 *)
val of_seq : (key * 'a) sequence -> 'a t
(** From the given bindings, added in order.
@deprecated use {!of_iter} or {!of_std_seq} *)
[@@ocaml.deprecated "use of_iter or of_std_seq"]
val add_iter_count : int t -> key iter -> unit
(** [add_iter_count tbl i] increments the count of each element of [i]
by calling {!incr}. This is useful for counting how many times each
@ -266,14 +215,6 @@ module type S = sig
element of [seq] occurs.
@since 2.8 *)
val add_seq_count : int t -> key sequence -> unit
(** [add_seq_count tbl seq] increments the count of each element of [seq]
by calling {!incr}. This is useful for counting how many times each
element of [seq] occurs.
@since 0.16
@deprecated use {!add_iter_count} or {!add_std_seq_count} *)
[@@ocaml.deprecated "use add_iter_count or add_std_seq_count"]
val of_iter_count : key iter -> int t
(** Like {!add_seq_count}, but allocates a new table and returns it.
@since 2.8 *)
@ -282,12 +223,6 @@ module type S = sig
(** Like {!add_seq_count}, but allocates a new table and returns it.
@since 2.8 *)
val of_seq_count : key sequence -> int t
(** Like {!add_seq_count}, but allocates a new table and returns it.
@since 0.16
@deprecated use {!of_iter_count} or {!of_std_seq_count} *)
[@@ocaml.deprecated "use add_iter_count or add_std_seq_count"]
val to_list : 'a t -> (key * 'a) list
(** List of bindings (order unspecified). *)

View file

@ -59,7 +59,7 @@ end
(*$QR & ~count:30
Q.(list_of_size Gen.(return 1_000) int) (fun l ->
(* put elements into a heap *)
let h = H.of_seq (Iter.of_list l) in
let h = H.of_iter (Iter.of_list l) in
OUnit.assert_equal 1_000 (H.size h);
let l' = extract_list h in
is_sorted l'
@ -70,10 +70,10 @@ end
(*$QR & ~count:30
Q.(list_of_size Gen.(return 1_000) int) (fun l ->
(* put elements into a heap *)
let h = H.of_seq (Iter.of_list l) in
let h = H.of_iter (Iter.of_list l) in
let h = H.filter (fun x->x mod 2=0) h in
OUnit.assert_bool "all odd"
(H.to_seq h |> Iter.for_all (fun x -> x mod 2 = 0));
(H.to_iter h |> Iter.for_all (fun x -> x mod 2 = 0));
let l' = extract_list h in
is_sorted l'
)
@ -82,8 +82,8 @@ end
(*$QR
Q.(list_of_size Gen.(return 1_000) int) (fun l ->
(* put elements into a heap *)
let h = H.of_seq (Iter.of_list l) in
let l' = H.to_seq_sorted h |> Iter.to_list in
let h = H.of_iter (Iter.of_list l) in
let l' = H.to_iter_sorted h |> Iter.to_list in
is_sorted l'
)
*)
@ -153,7 +153,7 @@ module type S = sig
(** {2 Conversions}
The interface of [of_gen], [of_seq], [of_klist]
The interface of [of_gen], [of_iter], [of_klist]
has changed since 0.16 (the old signatures
are now [add_seq], [add_gen], [add_klist]). *)
@ -180,11 +180,6 @@ module type S = sig
(** Like {!add_list}.
@since 2.8 *)
val add_seq : t -> elt sequence -> t (** @since 0.16 *)
(** Like {!add_list}.
@deprecated use {!add_iter} or {!add_std_seq} instead *)
[@@ocaml.deprecated "use add_iter. For the standard Seq, see {!add_std_seq}"]
val of_iter : elt iter -> t
(** Build a heap from a given [iter]. Complexity: [O(n log n)].
@since 2.8 *)
@ -193,11 +188,6 @@ module type S = sig
(** Build a heap from a given [Seq.t]. Complexity: [O(n log n)].
@since 2.8 *)
val of_seq : elt sequence -> t
(** Build a heap from a given [sequence]. Complexity: [O(n log n)].
@deprecated use {!of_iter} or {!of_std_seq} instead *)
[@@ocaml.deprecated "use of_iter. For the standard Seq, see {!of_std_seq}"]
val to_iter : t -> elt iter
(** Return a [iter] of the elements of the heap.
@since 2.8 *)
@ -206,11 +196,6 @@ module type S = sig
(** Return a [Seq.t] of the elements of the heap.
@since 2.8 *)
val to_seq : t -> elt sequence
(** Return a [sequence] of the elements of the heap.
@deprecated use {!to_iter} or {!to_std_seq} instead *)
[@@ocaml.deprecated "use to_iter. For the standard Seq, see {!to_std_seq}"]
val to_iter_sorted : t -> elt iter
(** Iterate on the elements, in increasing order.
@since 2.8 *)
@ -219,12 +204,6 @@ module type S = sig
(** Iterate on the elements, in increasing order.
@since 2.8 *)
val to_seq_sorted : t -> elt sequence
(** Iterate on the elements, in increasing order.
@since 1.1
@deprecated use {!to_iter_sorted} or {!to_std_seq_sorted} instead *)
[@@ocaml.deprecated "use to_iter_sorted or to_std_seq_sorted"]
val add_klist : t -> elt klist -> t (** @since 0.16 *)
val of_klist : elt klist -> t
@ -418,11 +397,6 @@ module Make(E : PARTIAL_ORD) : S with type elt = E.t = struct
| None -> Seq.Nil
| Some (h', x) -> Seq.Cons (x, to_std_seq_sorted h')
let add_seq = add_iter
let of_seq = of_iter
let to_seq = to_iter
let to_seq_sorted = to_iter_sorted
let rec add_klist h l = match l() with
| `Nil -> h
| `Cons (x, l') ->

View file

@ -2,7 +2,7 @@
(* This file is free software, part of containers. See file "license" for more details. *)
(** {1 Leftist Heaps}
Implementation following Okasaki's book. *)
@ -126,11 +126,6 @@ module type S = sig
(** Like {!add_list}.
@since 2.8 *)
val add_seq : t -> elt sequence -> t (** @since 0.16 *)
(** Like {!add_list}.
@deprecated use {!add_iter} or {!add_std_seq} instead *)
[@@ocaml.deprecated "use add_iter. For the standard Seq, see {!add_std_seq}"]
val of_iter : elt iter -> t
(** Build a heap from a given [iter]. Complexity: [O(n log n)].
@since 2.8 *)
@ -139,11 +134,6 @@ module type S = sig
(** Build a heap from a given [Seq.t]. Complexity: [O(n log n)].
@since 2.8 *)
val of_seq : elt sequence -> t
(** Build a heap from a given [sequence]. Complexity: [O(n log n)].
@deprecated use {!of_iter} or {!of_std_seq} instead *)
[@@ocaml.deprecated "use of_iter. For the standard Seq, see {!of_std_seq}"]
val to_iter : t -> elt iter
(** Return a [iter] of the elements of the heap.
@since 2.8 *)
@ -152,11 +142,6 @@ module type S = sig
(** Return a [Seq.t] of the elements of the heap.
@since 2.8 *)
val to_seq : t -> elt sequence
(** Return a [sequence] of the elements of the heap.
@deprecated use {!to_iter} or {!to_std_seq} instead *)
[@@ocaml.deprecated "use to_iter. For the standard Seq, see {!to_std_seq}"]
val to_iter_sorted : t -> elt iter
(** Iterate on the elements, in increasing order.
@since 2.8 *)
@ -165,12 +150,6 @@ module type S = sig
(** Iterate on the elements, in increasing order.
@since 2.8 *)
val to_seq_sorted : t -> elt sequence
(** Iterate on the elements, in increasing order.
@since 1.1
@deprecated use {!to_iter_sorted} or {!to_std_seq_sorted} instead *)
[@@ocaml.deprecated "use to_iter_sorted or to_std_seq_sorted"]
val add_klist : t -> elt klist -> t (** @since 0.16 *)
val of_klist : elt klist -> t

View file

@ -75,8 +75,6 @@ let read_chunks_gen ?(size=1024) ic =
in
next
let read_chunks = read_chunks_gen
let read_line ic =
try Some (input_line ic)
with End_of_file -> None
@ -88,8 +86,6 @@ let read_lines_gen ic =
else try Some (input_line ic)
with End_of_file -> (stop:=true; None)
let read_lines = read_lines_gen
let read_lines_l ic =
let l = ref [] in
try
@ -200,7 +196,7 @@ let write_lines_l oc l =
(fun (name, oc) ->
write_lines oc (Gen.of_list l);
flush oc;
l' := with_in name (fun ic -> read_lines ic |> Gen.to_list);
l' := with_in name (fun ic -> read_lines_gen ic |> Gen.to_list);
) ();
String.concat "\n" l = String.concat "\n" !l'
)

View file

@ -66,11 +66,6 @@ val with_in : ?mode:int -> ?flags:open_flag list ->
@raise Sys_error in case of error (same as {!open_in} and {!close_in}).
@param flags opening flags (default [[Open_text]]). [Open_rdonly] is used in any cases. *)
val read_chunks : ?size:int -> in_channel -> string gen
(** Read the channel's content into chunks of size [size].
@deprecated use {!read_chunks_gen} instead. *)
[@@ocaml.deprecated "use read_chunks_gen"]
val read_chunks_gen : ?size:int -> in_channel -> string gen
(** Read the channel's content into chunks of size [size].
{b NOTE} the generator must be used within the lifetime of the channel,
@ -80,11 +75,6 @@ val read_line : in_channel -> string option
(** Read a line from the channel. Returns [None] if the input is terminated.
The "\n" is removed from the line. *)
val read_lines : in_channel -> string gen
(** Read all lines. The generator should be traversed only once.
@deprecated use {!read_lines_gen} instead. *)
[@@ocaml.deprecated "use read_lines_gen"]
val read_lines_gen : in_channel -> string gen
(** Read all lines. The generator should be traversed only once.
{b NOTE} the generator must be used within the lifetime of the channel,

View file

@ -45,11 +45,6 @@ let hash x = Stdlib.abs (to_int x)
(** {2 Conversion} *)
let of_int_exn = of_int
let of_nativeint_exn = of_nativeint
let of_int32_exn = of_int32
let of_float_exn = of_float
let of_string_exn = of_string
let of_string x = try Some (of_string_exn x) with Failure _ -> None

View file

@ -115,11 +115,6 @@ val of_int : int -> t
(** Alias to {!Int64.of_int}.
NOTE: used to return an option, but the function actually never fails. *)
val of_int_exn : int -> t
(** Alias to {!Int64.of_int}.
@deprecated since 2.1, use {!Int64.of_int} instead. *)
[@@ocaml.deprecated "use Int64.of_int instead"]
val to_int32 : t -> int32
(** Convert the given 64-bit integer (type [int64]) to a
32-bit integer (type [int32]). The 64-bit integer
@ -130,11 +125,6 @@ val of_int32 : int32 -> t
(** Alias to {!Int64.of_int32}.
NOTE: use to return an option, but the function actually never fails. *)
val of_int32_exn : int32 -> t
(** Alias to {!Int64.of_int32}.
@deprecated since 2.1, use {!Int64.of_int32} instead. *)
[@@ocaml.deprecated "use Int64.of_int32 instead"]
val to_nativeint : t -> nativeint
(** Convert the given 64-bit integer (type [int64]) to a
native integer. On 32-bit platforms, the 64-bit integer
@ -145,11 +135,6 @@ val of_nativeint : nativeint -> t
(** Alias to {!Int64.of_nativeint}.
NOTE: use to return an option, but the function actually never fails. *)
val of_nativeint_exn : nativeint -> t
(** Alias to {!Int64.of_nativeint}.
@deprecated since 2.1, use {!Int64.of_nativeint} instead. *)
[@@ocaml.deprecated "use Int64.of_nativeint instead"]
val to_float : t -> float
(** Convert the given 64-bit integer to a floating-point number. *)
@ -161,11 +146,6 @@ val of_float : float -> t
the number is outside the range \[{!CCInt64.min_int}, {!CCInt64.max_int}\].
NOTE: used to return an option, but the function never fails. *)
val of_float_exn : float -> t
(** Alias to {!Int64.of_float}.
@deprecated since 2.1, use {!Int64.of_float} instead. *)
[@@ocaml.deprecated "use Int64.of_float instead"]
val to_string : t -> string
(** Return the string representation of its argument, in decimal. *)

View file

@ -1666,7 +1666,6 @@ end
(** {2 Conversions} *)
type 'a iter = ('a -> unit) -> unit
type 'a sequence = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
type 'a printer = Format.formatter -> 'a -> unit
@ -1739,12 +1738,9 @@ let of_std_seq l =
direct direct_depth_default_ l
(*$Q
Q.(list int) (fun l -> of_seq (to_seq l) = l)
Q.(list int) (fun l -> of_iter (to_iter l) = l)
*)
let to_seq = to_iter
let of_seq = of_iter
let to_gen l =
let l = ref l in
fun () ->

View file

@ -3,11 +3,6 @@
(** {1 Complements to list} *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
@ -727,11 +722,6 @@ val to_std_seq : 'a t -> 'a Seq.t
(** Return a [Seq.t] of the elements of the list.
@since 2.8 *)
val to_seq : 'a t -> 'a sequence
(** Return a [sequence] of the elements of the list.
@deprecated use {!to_iter} or {!to_std_seq} instead *)
[@@ocaml.deprecated "use to_iter or to_std_seq"]
val of_iter : 'a iter -> 'a t
(** Build a list from a given [iter].
In the result, elements appear in the same order as they did in the source [iter].
@ -746,12 +736,6 @@ val of_std_seq : 'a Seq.t -> 'a t
In the result, elements appear in the same order as they did in the source [seq].
@since 2.8 *)
val of_seq : 'a sequence -> 'a t
(** Build a list from a given [sequence].
In the result, elements appear in the same order as they did in the source [sequence].
@deprecated use {!of_iter} or {!of_std_seq} instead *)
[@@ocaml.deprecated "use of_iter or of_std_seq"]
val to_gen : 'a t -> 'a gen
(** Return a [gen] of the elements of the list. *)

View file

@ -3,11 +3,6 @@
(** {1 Complements to list} *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
@ -731,11 +726,6 @@ val to_std_seq : 'a t -> 'a Seq.t
(** Return a [Seq.t] of the elements of the list.
@since 2.8 *)
val to_seq : 'a t -> 'a sequence
(** Return a [sequence] of the elements of the list.
@deprecated use {!to_iter} or {!to_std_seq} instead *)
[@@ocaml.deprecated "use to_iter or to_std_seq"]
val of_iter : 'a iter -> 'a t
(** Build a list from a given [iter].
In the result, elements appear in the same order as they did in the source [iter].
@ -750,12 +740,6 @@ val of_std_seq : 'a Seq.t -> 'a t
In the result, elements appear in the same order as they did in the source [seq].
@since 2.8 *)
val of_seq : 'a sequence -> 'a t
(** Build a list from a given [sequence].
In the result, elements appear in the same order as they did in the source [sequence].
@deprecated use {!of_iter} or {!of_std_seq} instead *)
[@@ocaml.deprecated "use of_iter or of_std_seq"]
val to_gen : 'a t -> 'a gen
(** Return a [gen] of the elements of the list. *)

View file

@ -4,7 +4,6 @@
(** {1 Extensions of Standard Map} *)
type 'a iter = ('a -> unit) -> unit
type 'a sequence = ('a -> unit) -> unit
type 'a printer = Format.formatter -> 'a -> unit
module type OrderedType = Map.OrderedType
@ -81,20 +80,6 @@ module type S = sig
(** Like {!to_list}.
@since 2.8 *)
val of_seq : (key * 'a) sequence -> 'a t
(** Like {!of_list}.
@deprecated use {!of_iter} instead. *)
[@@ocaml.deprecated "use of_iter instead"]
val add_seq : 'a t -> (key * 'a) sequence -> 'a t
(** @since 0.14
@deprecated use {!add_iter} instead. *)
[@@ocaml.deprecated "use add_iter instead"]
val to_seq : 'a t -> (key * 'a) sequence
(** @deprecated use {!to_iter} instead. *)
[@@ocaml.deprecated "use to_iter instead"]
val of_list : (key * 'a) list -> 'a t
(** Build a map from the given list of bindings [k_i -> v_i],
added in order using {!add}.
@ -225,10 +210,6 @@ module Make(O : Map.OrderedType) = struct
let to_iter m yield =
iter (fun k v -> yield (k,v)) m
let add_seq = add_iter
let of_seq = of_iter
let to_seq = to_iter
let keys m yield =
iter (fun k _ -> yield k) m

View file

@ -6,11 +6,6 @@
Provide useful functions and iterators on [Map.S]
@since 0.5 *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
@ -92,20 +87,6 @@ module type S = sig
(** Like {!to_list}.
@since 2.8 *)
val of_seq : (key * 'a) sequence -> 'a t
(** Like {!of_list}.
@deprecated use {!of_iter} instead. *)
[@@ocaml.deprecated "use of_iter instead"]
val add_seq : 'a t -> (key * 'a) sequence -> 'a t
(** @since 0.14
@deprecated use {!add_iter} instead. *)
[@@ocaml.deprecated "use add_iter instead"]
val to_seq : 'a t -> (key * 'a) sequence
(** @deprecated use {!to_iter} instead. *)
[@@ocaml.deprecated "use to_iter instead"]
val of_list : (key * 'a) list -> 'a t
(** Build a map from the given list of bindings [k_i -> v_i],
added in order using {!add}.

View file

@ -177,7 +177,7 @@ end
include Infix
type 'a sequence = ('a -> unit) -> unit
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a printer = Format.formatter -> 'a -> unit
type 'a random_gen = Random.State.t -> 'a
@ -187,7 +187,7 @@ let random g st =
exception ExitChoice
let choice_seq s =
let choice_iter s =
let r = ref None in
begin try
s (function
@ -199,9 +199,20 @@ let choice_seq s =
!r
(*$T
choice_seq (Iter.of_list [None; Some 1; Some 2]) = Some 1
choice_seq Iter.empty = None
choice_seq (Iter.repeat None |> Iter.take 100) = None
choice_iter (Iter.of_list [None; Some 1; Some 2]) = Some 1
choice_iter Iter.empty = None
choice_iter (Iter.repeat None |> Iter.take 100) = None
*)
let rec choice_seq s = match s() with
| Seq.Nil -> None
| Seq.Cons (Some x, _) -> Some x
| Seq.Cons (None, tl) -> choice_seq tl
(*$T
choice_seq (CCSeq.of_list [None; Some 1; Some 2]) = Some 1
choice_seq CCSeq.empty = None
choice_seq (CCSeq.repeat None |> CCSeq.take 100) = None
*)
let to_gen o =

View file

@ -186,17 +186,20 @@ val to_result_lazy : (unit -> 'e) -> 'a t -> ('a, 'e) result
val of_result : ('a, _) result -> 'a t
(** @since 1.2 *)
type 'a sequence = ('a -> unit) -> unit
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a printer = Format.formatter -> 'a -> unit
type 'a random_gen = Random.State.t -> 'a
val random : 'a random_gen -> 'a t random_gen
val choice_seq : 'a t sequence -> 'a t
val choice_iter : 'a t iter -> 'a t
(** [choice_seq s] is similar to {!choice}, but works on sequences.
It returns the first [Some x] occurring in [s], or [None] otherwise.
@since 0.13 *)
@since 3.0 *)
val choice_seq : 'a t Seq.t -> 'a t
(** @since 3.0 *)
val to_gen : 'a t -> 'a gen
@ -204,14 +207,8 @@ val to_std_seq : 'a t -> 'a Seq.t
(** Same as {!Stdlib.Option.to_seq}
@since 2.8 *)
val to_iter : 'a t -> 'a sequence
val to_iter : 'a t -> 'a iter
(** Returns an internal iterator, like in the library [Iter].
@since 2.8 *)
val to_seq : 'a t -> 'a sequence
(** Previous name for {!to_iter}
@deprecated use {!to_iter} or {!to_std_seq} instead *)
[@@ocaml.deprecated "use to_iter or to_std_seq"]
val pp : 'a printer -> 'a t printer

View file

@ -93,10 +93,6 @@ let sample_without_duplicates (type elt) ~cmp k (rng:elt t) st=
if k<=0 then invalid_arg "sample_without_duplicates";
aux S.empty k
(* deprecated *)
let sample_without_replacement ~compare k rng =
sample_without_duplicates ~cmp:compare k rng
let list_seq l st = List.map (fun f -> f st) l
let split i st =
@ -123,7 +119,7 @@ let _diff_list ~last l =
let split_list i ~len st =
if len <= 1 then invalid_arg "Random.split_list";
if i >= len then (
let xs = sample_without_replacement ~compare (len-1) (int_range 1 (i-1)) st in
let xs = sample_without_duplicates ~cmp:compare (len-1) (int_range 1 (i-1)) st in
_diff_list ~last:i (0::xs)
) else
None

View file

@ -59,16 +59,6 @@ val replicate : int -> 'a t -> 'a list t
(** [replicate n g] makes a list of [n] elements which are all generated
randomly using [g]. *)
val sample_without_replacement:
compare:('a -> 'a -> int) -> int -> 'a t -> 'a list t
(** [sample_without_replacement n g] makes a list of [n] elements which are all
generated randomly using [g] with the added constraint that none of the generated
random values are equal.
@deprecated use sample_without_duplicates instead
@raise Invalid_argument if [n <= 0].
@since 0.15 *)
[@@ocaml.deprecated "use sample_without_duplicates instead"]
val sample_without_duplicates:
cmp:('a -> 'a -> int) -> int -> 'a t -> 'a list t
(** [sample_without_replacement n g] makes a list of [n] elements which are all

View file

@ -8,7 +8,7 @@
type 'a printer = Format.formatter -> 'a -> unit
type 'a ord = 'a -> 'a -> int
type 'a eq = 'a -> 'a -> bool
type 'a sequence = ('a -> unit) -> unit
type 'a iter = ('a -> unit) -> unit
type 'a t = 'a ref
@ -38,6 +38,6 @@ let swap a b =
b := x
let to_list r = [!r]
let to_seq r yield = yield !r
let to_iter r yield = yield !r
let pp pp_x out r = pp_x out !r

View file

@ -7,7 +7,7 @@
type 'a printer = Format.formatter -> 'a -> unit
type 'a ord = 'a -> 'a -> int
type 'a eq = 'a -> 'a -> bool
type 'a sequence = ('a -> unit) -> unit
type 'a iter = ('a -> unit) -> unit
type 'a t = 'a ref
@ -41,6 +41,7 @@ val equal : 'a eq -> 'a t eq
val to_list : 'a t -> 'a list
val to_seq : 'a t -> 'a sequence
val to_iter : 'a t -> 'a iter
(** @since 3.0 *)
val pp : 'a printer -> 'a t printer

View file

@ -3,7 +3,6 @@
(** {1 Error Monad} *)
type 'a iter = ('a -> unit) -> unit
type 'a sequence = ('a -> unit) -> unit
type 'a equal = 'a -> 'a -> bool
type 'a ord = 'a -> 'a -> int
type 'a printer = Format.formatter -> 'a -> unit
@ -240,7 +239,7 @@ let flatten_l l =
exception LocalExit
let fold_seq f acc seq =
let fold_iter f acc seq =
let err = ref None in
try
let acc = ref acc in
@ -252,7 +251,7 @@ let fold_seq f acc seq =
with LocalExit ->
match !err with None -> assert false | Some s -> Error s
let fold_l f acc l = fold_seq f acc (fun k -> List.iter k l)
let fold_l f acc l = fold_iter f acc (fun k -> List.iter k l)
(** {2 Misc} *)
@ -345,8 +344,6 @@ let to_iter e k = match e with
| Ok x -> k x
| Error _ -> ()
let to_seq = to_iter
type ('a, 'b) error = [`Ok of 'a | `Error of 'b]
let of_err = function

View file

@ -6,11 +6,6 @@
@since 0.16 *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
@ -221,7 +216,8 @@ val map_l : ('a -> ('b, 'err) t) -> 'a list -> ('b list, 'err) t
val fold_l : ('b -> 'a -> ('b, 'err) t) -> 'b -> 'a list -> ('b, 'err) t
val fold_seq : ('b -> 'a -> ('b, 'err) t) -> 'b -> 'a sequence -> ('b, 'err) t
val fold_iter : ('b -> 'a -> ('b, 'err) t) -> 'b -> 'a iter -> ('b, 'err) t
(** @since 3.0 *)
(** {2 Misc} *)
@ -268,10 +264,6 @@ val to_iter : ('a, _) t -> 'a iter
val to_std_seq : ('a, _) t -> 'a Seq.t
(** @since 2.8 *)
val to_seq : ('a, _) t -> 'a sequence
(** @deprecated use {!to_iter} or {!to_std_seq} *)
[@@ocaml.deprecated "use to_iter or to_std_seq"]
type ('a, 'b) error = [`Ok of 'a | `Error of 'b]
val of_err : ('a, 'b) error -> ('a, 'b) t

541
src/core/CCSeq.ml Normal file
View file

@ -0,0 +1,541 @@
(* This file is free software, part of containers. See file "license" for more details. *)
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a equal = 'a -> 'a -> bool
type 'a ord = 'a -> 'a -> int
type 'a printer = Format.formatter -> 'a -> unit
type + 'a t = unit -> 'a node
and +'a node = 'a Seq.node =
| Nil
| Cons of 'a * 'a t
let nil () = Nil
let cons a b () = Cons (a,b)
let empty = nil
let singleton x () = Cons (x, nil)
let rec _forever x () = Cons (x, _forever x)
let rec _repeat n x () =
if n<=0 then Nil else Cons (x, _repeat (n-1) x)
let repeat ?n x = match n with
| None -> _forever x
| Some n -> _repeat n x
(*$T
repeat ~n:4 0 |> to_list = [0;0;0;0]
repeat ~n:0 1 |> to_list = []
repeat 1 |> take 20 |> to_list = (repeat ~n:20 1 |> to_list)
*)
let is_empty l = match l () with
| Nil -> true
| Cons _ -> false
let head_exn l = match l() with | Nil -> raise Not_found | Cons (x, _) -> x
let head l = match l() with Nil -> None | Cons (x, _) -> Some x
let tail_exn l = match l() with | Nil -> raise Not_found | Cons (_, l) -> l
let tail l = match l() with | Nil -> None | Cons (_, l) -> Some l
let rec equal eq l1 l2 = match l1(), l2() with
| Nil, Nil -> true
| Nil, _
| _, Nil -> false
| Cons (x1,l1'), Cons (x2,l2') ->
eq x1 x2 && equal eq l1' l2'
let rec compare cmp l1 l2 = match l1(), l2() with
| Nil, Nil -> 0
| Nil, _ -> -1
| _, Nil -> 1
| Cons (x1,l1'), Cons (x2,l2') ->
let c = cmp x1 x2 in
if c = 0 then compare cmp l1' l2' else c
let rec fold f acc res = match res () with
| Nil -> acc
| Cons (s, cont) -> fold f (f acc s) cont
let fold_left = fold
let rec iter f l = match l () with
| Nil -> ()
| Cons (x, l') -> f x; iter f l'
let iteri f l =
let rec aux f l i = match l() with
| Nil -> ()
| Cons (x, l') ->
f i x;
aux f l' (i+1)
in
aux f l 0
let length l = fold (fun acc _ -> acc+1) 0 l
let rec take n (l:'a t) () =
if n=0 then Nil
else match l () with
| Nil -> Nil
| Cons (x,l') -> Cons (x, take (n-1) l')
let rec take_while p l () = match l () with
| Nil -> Nil
| Cons (x,l') ->
if p x then Cons (x, take_while p l') else Nil
(*$T
of_list [1;2;3;4] |> take_while (fun x->x < 4) |> to_list = [1;2;3]
*)
let rec drop n (l:'a t) () = match l () with
| l' when n=0 -> l'
| Nil -> Nil
| Cons (_,l') -> drop (n-1) l' ()
let rec drop_while p l () = match l() with
| Nil -> Nil
| Cons (x,l') when p x -> drop_while p l' ()
| Cons _ as res -> res
(*$Q
(Q.pair (Q.list Q.small_int) Q.small_int) (fun (l,n) -> \
let s = of_list l in let s1, s2 = take n s, drop n s in \
append s1 s2 |> to_list = l )
*)
let rec map f l () = match l () with
| Nil -> Nil
| Cons (x, l') -> Cons (f x, map f l')
(*$T
(map ((+) 1) (1 -- 5) |> to_list) = (2 -- 6 |> to_list)
*)
let mapi f l =
let rec aux f l i () = match l() with
| Nil -> Nil
| Cons (x, tl) ->
Cons (f i x, aux f tl (i+1))
in
aux f l 0
(*$T
mapi (fun i x -> i,x) (1 -- 3) |> to_list = [0, 1; 1, 2; 2, 3]
*)
let rec fmap f (l:'a t) () = match l() with
| Nil -> Nil
| Cons (x, l') ->
begin match f x with
| None -> fmap f l' ()
| Some y -> Cons (y, fmap f l')
end
(*$T
fmap (fun x -> if x mod 2=0 then Some (x*3) else None) (1--10) |> to_list \
= [6;12;18;24;30]
*)
let rec filter p l () = match l () with
| Nil -> Nil
| Cons (x, l') ->
if p x
then Cons (x, filter p l')
else filter p l' ()
let rec append l1 l2 () = match l1 () with
| Nil -> l2 ()
| Cons (x, l1') -> Cons (x, append l1' l2)
let rec cycle l () = append l (cycle l) ()
(*$T
cycle (of_list [1;2]) |> take 5 |> to_list = [1;2;1;2;1]
cycle (of_list [1; ~-1]) |> take 100_000 |> fold (+) 0 = 0
*)
let rec unfold f acc () = match f acc with
| None -> Nil
| Some (x, acc') -> Cons (x, unfold f acc')
(*$T
let f = function 10 -> None | x -> Some (x, x+1) in \
unfold f 0 |> to_list = [0;1;2;3;4;5;6;7;8;9]
*)
let rec flat_map f l () = match l () with
| Nil -> Nil
| Cons (x, l') ->
_flat_map_app f (f x) l' ()
and _flat_map_app f l l' () = match l () with
| Nil -> flat_map f l' ()
| Cons (x, tl) ->
Cons (x, _flat_map_app f tl l')
let product_with f l1 l2 =
let rec _next_left h1 tl1 h2 tl2 () =
match tl1() with
| Nil -> _next_right ~die:true h1 tl1 h2 tl2 ()
| Cons (x, tl1') ->
_map_list_left x h2
(_next_right ~die:false (x::h1) tl1' h2 tl2)
()
and _next_right ~die h1 tl1 h2 tl2 () =
match tl2() with
| Nil when die -> Nil
| Nil -> _next_left h1 tl1 h2 tl2 ()
| Cons (y, tl2') ->
_map_list_right h1 y
(_next_left h1 tl1 (y::h2) tl2')
()
and _map_list_left x l kont () = match l with
| [] -> kont()
| y::l' -> Cons (f x y, _map_list_left x l' kont)
and _map_list_right l y kont () = match l with
| [] -> kont()
| x::l' -> Cons (f x y, _map_list_right l' y kont)
in
_next_left [] l1 [] l2
let product l1 l2 =
product_with (fun x y -> x,y) l1 l2
let rec group eq l () = match l() with
| Nil -> Nil
| Cons (x, l') ->
Cons (cons x (take_while (eq x) l'), group eq (drop_while (eq x) l'))
(*$T
of_list [1;1;1;2;2;3;3;1] |> group (=) |> map to_list |> to_list = \
[[1;1;1]; [2;2]; [3;3]; [1]]
*)
let rec _uniq eq prev l () = match prev, l() with
| _, Nil -> Nil
| None, Cons (x, l') ->
Cons (x, _uniq eq (Some x) l')
| Some y, Cons (x, l') ->
if eq x y
then _uniq eq prev l' ()
else Cons (x, _uniq eq (Some x) l')
let uniq eq l = _uniq eq None l
let rec filter_map f l () = match l() with
| Nil -> Nil
| Cons (x, l') ->
begin match f x with
| None -> filter_map f l' ()
| Some y -> Cons (y, filter_map f l')
end
let flatten l = flat_map (fun x->x) l
let range i j =
let rec aux i j () =
if i=j then Cons(i, nil)
else if i<j then Cons (i, aux (i+1) j)
else Cons (i, aux (i-1) j)
in aux i j
(*$T
range 0 5 |> to_list = [0;1;2;3;4;5]
range 0 0 |> to_list = [0]
range 5 2 |> to_list = [5;4;3;2]
*)
let (--) = range
let (--^) i j =
if i=j then empty
else if i<j then range i (j-1)
else range i (j+1)
(*$T
1 --^ 5 |> to_list = [1;2;3;4]
5 --^ 1 |> to_list = [5;4;3;2]
1 --^ 2 |> to_list = [1]
0 --^ 0 |> to_list = []
*)
let rec fold2 f acc l1 l2 = match l1(), l2() with
| Nil, _
| _, Nil -> acc
| Cons(x1,l1'), Cons(x2,l2') ->
fold2 f (f acc x1 x2) l1' l2'
let rec map2 f l1 l2 () = match l1(), l2() with
| Nil, _
| _, Nil -> Nil
| Cons(x1,l1'), Cons(x2,l2') ->
Cons (f x1 x2, map2 f l1' l2')
let rec iter2 f l1 l2 = match l1(), l2() with
| Nil, _
| _, Nil -> ()
| Cons(x1,l1'), Cons(x2,l2') ->
f x1 x2; iter2 f l1' l2'
let rec for_all2 f l1 l2 = match l1(), l2() with
| Nil, _
| _, Nil -> true
| Cons(x1,l1'), Cons(x2,l2') ->
f x1 x2 && for_all2 f l1' l2'
let rec exists2 f l1 l2 = match l1(), l2() with
| Nil, _
| _, Nil -> false
| Cons(x1,l1'), Cons(x2,l2') ->
f x1 x2 || exists2 f l1' l2'
let rec merge cmp l1 l2 () = match l1(), l2() with
| Nil, tl2 -> tl2
| tl1, Nil -> tl1
| Cons(x1,l1'), Cons(x2,l2') ->
if cmp x1 x2 < 0
then Cons (x1, merge cmp l1' l2)
else Cons (x2, merge cmp l1 l2')
let rec zip a b () = match a(), b() with
| Nil, _
| _, Nil -> Nil
| Cons (x, a'), Cons (y, b') -> Cons ((x,y), zip a' b')
let unzip l =
let rec first l () = match l() with
| Nil -> Nil
| Cons ((x,_), tl) -> Cons (x, first tl)
and second l () = match l() with
| Nil -> Nil
| Cons ((_, y), tl) -> Cons (y, second tl)
in
first l, second l
(*$Q
Q.(list (pair int int)) (fun l -> \
let l = of_list l in let a, b = unzip l in equal (=) l (zip a b))
*)
(** {2 Implementations} *)
let return x () = Cons (x, nil)
let pure = return
let (>>=) xs f = flat_map f xs
let (>|=) xs f = map f xs
let (<*>) fs xs = product_with (fun f x -> f x) fs xs
(** {2 Conversions} *)
let rec _to_rev_list acc l = match l() with
| Nil -> acc
| Cons (x,l') -> _to_rev_list (x::acc) l'
let to_rev_list l = _to_rev_list [] l
let to_list l =
let rec direct i (l:'a t) = match l () with
| Nil -> []
| _ when i=0 -> List.rev (_to_rev_list [] l)
| Cons (x, f) -> x :: direct (i-1) f
in
direct 200 l
let of_list l =
let rec aux l () = match l with
| [] -> Nil
| x::l' -> Cons (x, aux l')
in aux l
let of_array a =
let rec aux a i () =
if i=Array.length a then Nil
else Cons (a.(i), aux a (i+1))
in
aux a 0
let to_array l =
match l() with
| Nil -> [| |]
| Cons (x, _) ->
let n = length l in
let a = Array.make n x in (* need first elem to create [a] *)
iteri
(fun i x -> a.(i) <- x)
l;
a
(*$Q
Q.(array int) (fun a -> of_array a |> to_array = a)
*)
(*$T
of_array [| 1; 2; 3 |] |> to_list = [1;2;3]
of_list [1;2;3] |> to_array = [| 1; 2; 3; |]
*)
let rec to_iter res k = match res () with
| Nil -> ()
| Cons (s, f) -> k s; to_iter f k
let to_gen l =
let l = ref l in
fun () ->
match !l () with
| Nil -> None
| Cons (x,l') ->
l := l';
Some x
type 'a of_gen_state =
| Of_gen_thunk of 'a gen
| Of_gen_saved of 'a node
let of_gen g =
let rec consume r () = match !r with
| Of_gen_saved cons -> cons
| Of_gen_thunk g ->
begin match g() with
| None ->
r := Of_gen_saved Nil;
Nil
| Some x ->
let tl = consume (ref (Of_gen_thunk g)) in
let l = Cons (x, tl) in
r := Of_gen_saved l;
l
end
in
consume (ref (Of_gen_thunk g))
(*$R
let g = let n = ref 0 in fun () -> Some (incr n; !n) in
let l = of_gen g in
assert_equal [1;2;3;4;5;6;7;8;9;10] (take 10 l |> to_list);
assert_equal [1;2;3;4;5;6;7;8;9;10] (take 10 l |> to_list);
assert_equal [11;12] (drop 10 l |> take 2 |> to_list);
*)
let sort ~cmp l =
let l = to_list l in
of_list (List.sort cmp l)
let sort_uniq ~cmp l =
let l = to_list l in
uniq (fun x y -> cmp x y = 0) (of_list (List.sort cmp l))
type 'a memoize =
| MemoThunk
| MemoSave of 'a node
let rec memoize f =
let r = ref MemoThunk in
fun () -> match !r with
| MemoSave l -> l
| MemoThunk ->
let l = match f() with
| Nil -> Nil
| Cons (x, tail) -> Cons (x, memoize tail)
in
r := MemoSave l;
l
(*$R
let printer = Q.Print.(list int) in
let gen () =
let rec l = let r = ref 0 in fun () -> incr r; Cons (!r, l) in l
in
let l1 = gen () in
assert_equal ~printer [1;2;3;4] (take 4 l1 |> to_list);
assert_equal ~printer [5;6;7;8] (take 4 l1 |> to_list);
let l2 = gen () |> memoize in
assert_equal ~printer [1;2;3;4] (take 4 l2 |> to_list);
assert_equal ~printer [1;2;3;4] (take 4 l2 |> to_list);
*)
(** {2 Fair Combinations} *)
let rec interleave a b () = match a() with
| Nil -> b ()
| Cons (x, tail) -> Cons (x, interleave b tail)
let rec fair_flat_map f a () = match a() with
| Nil -> Nil
| Cons (x, tail) ->
let y = f x in
interleave y (fair_flat_map f tail) ()
let rec fair_app f a () = match f() with
| Nil -> Nil
| Cons (f1, fs) ->
interleave (map f1 a) (fair_app fs a) ()
let (>>-) a f = fair_flat_map f a
let (<.>) f a = fair_app f a
(*$T
interleave (of_list [1;3;5]) (of_list [2;4;6]) |> to_list = [1;2;3;4;5;6]
fair_app (of_list [(+)1; ( * ) 3]) (of_list [1; 10]) \
|> to_list |> List.sort Stdlib.compare = [2; 3; 11; 30]
*)
(** {2 Infix} *)
module Infix = struct
let (>>=) = (>>=)
let (>|=) = (>|=)
let (<*>) = (<*>)
let (>>-) = (>>-)
let (<.>) = (<.>)
let (--) = (--)
let (--^) = (--^)
end
(** {2 Monadic Operations} *)
module type MONAD = sig
type 'a t
val return : 'a -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
end
module Traverse(M : MONAD) = struct
open M
let map_m f l =
let rec aux acc l = match l () with
| Nil -> return (of_list (List.rev acc))
| Cons (x,l') ->
f x >>= fun x' ->
aux (x' :: acc) l'
in
aux [] l
let sequence_m l = map_m (fun x->x) l
let rec fold_m f acc l = match l() with
| Nil -> return acc
| Cons (x,l') ->
f acc x >>= fun acc' -> fold_m f acc' l'
end
(** {2 IO} *)
let pp ?(sep=",") pp_item fmt l =
let rec pp fmt l = match l() with
| Nil -> ()
| Cons (x,l') ->
Format.pp_print_string fmt sep;
Format.pp_print_cut fmt ();
pp_item fmt x;
pp fmt l'
in
match l() with
| Nil -> ()
| Cons (x,l') -> pp_item fmt x; pp fmt l'

277
src/core/CCSeq.mli Normal file
View file

@ -0,0 +1,277 @@
(* This file is free software, part of containers. See file "license" for more details. *)
(** {1 Helpers for the standard {b Seq} type}
See {{: https://github.com/c-cube/oseq/} oseq} for a richer API.
*)
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a equal = 'a -> 'a -> bool
type 'a ord = 'a -> 'a -> int
type 'a printer = Format.formatter -> 'a -> unit
(** {2 Basics} *)
type + 'a t = unit -> 'a node
and +'a node = 'a Seq.node =
| Nil
| Cons of 'a * 'a t
val nil : 'a t
val empty : 'a t
val cons : 'a -> 'a t -> 'a t
val singleton : 'a -> 'a t
val repeat : ?n:int -> 'a -> 'a t
(** [repeat ~n x] repeats [x] [n] times then stops. If [n] is omitted,
then [x] is repeated forever.
@since 0.3.3 *)
val cycle : 'a t -> 'a t
(** Cycle through the iterator infinitely. The iterator shouldn't be empty.
@since 0.3.3 *)
val unfold : ('b -> ('a * 'b) option) -> 'b -> 'a t
(** [unfold f acc] calls [f acc] and:
- if [f acc = Some (x, acc')], yield [x], continue with [unfold f acc'].
- if [f acc = None], stops.
@since 0.13 *)
val is_empty : 'a t -> bool
val head : 'a t -> 'a option
(** Head of the list.
@since 0.13 *)
val head_exn : 'a t -> 'a
(** Unsafe version of {!head}.
@raise Not_found if the list is empty.
@since 0.13 *)
val tail : 'a t -> 'a t option
(** Tail of the list.
@since 0.13 *)
val tail_exn : 'a t -> 'a t
(** Unsafe version of {!tail}.
@raise Not_found if the list is empty.
@since 0.13 *)
val equal : 'a equal -> 'a t equal
(** Equality step by step. Eager. *)
val compare : 'a ord -> 'a t ord
(** Lexicographic comparison. Eager. *)
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
(** Fold on values. *)
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
(** Alias for {!fold} *)
val iter : ('a -> unit) -> 'a t -> unit
val iteri : (int -> 'a -> unit) -> 'a t -> unit
(** Iterate with index (starts at 0).
@since 0.13 *)
val length : _ t -> int
(** Number of elements in the list.
Will not terminate if the list if infinite:
use (for instance) {!take} to make the list finite if necessary. *)
val take : int -> 'a t -> 'a t
val take_while : ('a -> bool) -> 'a t -> 'a t
val drop : int -> 'a t -> 'a t
val drop_while : ('a -> bool) -> 'a t -> 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t
(** Map with index (starts at 0).
@since 0.13 *)
val fmap : ('a -> 'b option) -> 'a t -> 'b t
val filter : ('a -> bool) -> 'a t -> 'a t
val append : 'a t -> 'a t -> 'a t
val product_with : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
(** Fair product of two (possibly infinite) lists into a new list. Lazy.
The first parameter is used to combine each pair of elements.
@since 0.3.3 *)
val product : 'a t -> 'b t -> ('a * 'b) t
(** Specialization of {!product_with} producing tuples.
@since 0.3.3 *)
val group : 'a equal -> 'a t -> 'a t t
(** [group eq l] groups together consecutive elements that satisfy [eq]. Lazy.
For instance [group (=) [1;1;1;2;2;3;3;1]] yields
[[1;1;1]; [2;2]; [3;3]; [1]].
@since 0.3.3 *)
val uniq : 'a equal -> 'a t -> 'a t
(** [uniq eq l] returns [l] but removes consecutive duplicates. Lazy.
In other words, if several values that are equal follow one another,
only the first of them is kept.
@since 0.3.3 *)
val flat_map : ('a -> 'b t) -> 'a t -> 'b t
val filter_map : ('a -> 'b option) -> 'a t -> 'b t
val flatten : 'a t t -> 'a t
val range : int -> int -> int t
val (--) : int -> int -> int t
(** [a -- b] is the range of integers containing
[a] and [b] (therefore, never empty). *)
val (--^) : int -> int -> int t
(** [a -- b] is the integer range from [a] to [b], where [b] is excluded.
@since 0.17 *)
(** {2 Operations on two Collections} *)
val fold2 : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> 'a t -> 'b t -> 'acc
(** Fold on two collections at once. Stop at soon as one of them ends. *)
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
(** Map on two collections at once. Stop as soon as one of the
arguments is exhausted. *)
val iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unit
(** Iterate on two collections at once. Stop as soon as one of them ends. *)
val for_all2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
val exists2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
val merge : 'a ord -> 'a t -> 'a t -> 'a t
(** Merge two sorted iterators into a sorted iterator. *)
val zip : 'a t -> 'b t -> ('a * 'b) t
(** Combine elements pairwise. Stop as soon as one of the lists stops.
@since 0.13 *)
val unzip : ('a * 'b) t -> 'a t * 'b t
(** Split each tuple in the list.
@since 0.13 *)
(** {2 Misc} *)
val sort : cmp:'a ord -> 'a t -> 'a t
(** Eager sort. Require the iterator to be finite. [O(n ln(n))] time
and space.
@since 0.3.3 *)
val sort_uniq : cmp:'a ord -> 'a t -> 'a t
(** Eager sort that removes duplicate values. Require the iterator to be
finite. [O(n ln(n))] time and space.
@since 0.3.3 *)
val memoize : 'a t -> 'a t
(** Avoid recomputations by caching intermediate results.
@since 0.14 *)
(** {2 Fair Combinations} *)
val interleave : 'a t -> 'a t -> 'a t
(** Fair interleaving of both streams.
@since 0.13 *)
val fair_flat_map : ('a -> 'b t) -> 'a t -> 'b t
(** Fair version of {!flat_map}.
@since 0.13 *)
val fair_app : ('a -> 'b) t -> 'a t -> 'b t
(** Fair version of {!(<*>)}.
@since 0.13 *)
(** {2 Implementations}
@since 0.3.3 *)
val return : 'a -> 'a t
val pure : 'a -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val (>>-) : 'a t -> ('a -> 'b t) -> 'b t
(** Infix version of {! fair_flat_map}.
@since 0.13 *)
val (<.>) : ('a -> 'b) t -> 'a t -> 'b t
(** Infix version of {!fair_app}.
@since 0.13 *)
(** {2 Infix operators}
@since 0.17 *)
module Infix : sig
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val (>>-) : 'a t -> ('a -> 'b t) -> 'b t
val (<.>) : ('a -> 'b) t -> 'a t -> 'b t
val (--) : int -> int -> int t
val (--^) : int -> int -> int t
end
(** {2 Monadic Operations} *)
module type MONAD = sig
type 'a t
val return : 'a -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
end
module Traverse(M : MONAD) : sig
val sequence_m : 'a M.t t -> 'a t M.t
val fold_m : ('b -> 'a -> 'b M.t) -> 'b -> 'a t -> 'b M.t
val map_m : ('a -> 'b M.t) -> 'a t -> 'b t M.t
end
(** {2 Conversions} *)
val of_list : 'a list -> 'a t
val to_list : 'a t -> 'a list
(** Gather all values into a list. *)
val of_array : 'a array -> 'a t
(** Iterate on the array.
@since 0.13 *)
val to_array : 'a t -> 'a array
(** Convert into array. Iterate twice.
@since 0.13 *)
val to_rev_list : 'a t -> 'a list
(** Convert to a list, in reverse order. More efficient than {!to_list}. *)
val to_iter : 'a t -> 'a iter
val to_gen : 'a t -> 'a gen
val of_gen : 'a gen -> 'a t
(** [of_gen g] consumes the generator and caches intermediate results.
@since 0.13 *)
(** {2 IO} *)
val pp : ?sep:string -> 'a printer -> 'a t printer
(** Print the list with the given separator (default ",").
Do not print opening/closing delimiters. *)

View file

@ -4,7 +4,6 @@
(** {1 Wrapper around Set} *)
type 'a iter = ('a -> unit) -> unit
type 'a sequence = ('a -> unit) -> unit
type 'a printer = Format.formatter -> 'a -> unit
module type OrderedType = Set.OrderedType
@ -62,21 +61,6 @@ module type S = sig
(** [to_iter t] converts the set [t] to a [iter] of the elements.
@since 2.8 *)
val of_seq : elt sequence -> t
(** Build a set from the given [sequence] of elements.
@deprecated use {!of_iter} instead. *)
[@@ocaml.deprecated "use of_iter instead"]
val add_seq : t -> elt sequence -> t
(** @since 0.14
@deprecated use {!add_iter} instead. *)
[@@ocaml.deprecated "use add_iter instead"]
val to_seq : t -> elt sequence
(** [to_seq t] converts the set [t] to a [sequence] of the elements.
@deprecated use {!to_iter} instead. *)
[@@ocaml.deprecated "use to_iter instead"]
val add_list : t -> elt list -> t
(** @since 0.14 *)
@ -166,10 +150,6 @@ module Make(O : Map.OrderedType) = struct
let of_iter s = add_iter empty s
let to_iter s yield = iter yield s
let add_seq = add_iter
let of_seq = of_iter
let to_seq = to_iter
let add_list = List.fold_left (fun set x -> add x set)
let to_list = elements

View file

@ -5,11 +5,6 @@
@since 0.9 *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
@ -65,21 +60,6 @@ module type S = sig
(** [to_iter t] converts the set [t] to a [iter] of the elements.
@since 2.8 *)
val of_seq : elt sequence -> t
(** Build a set from the given [sequence] of elements.
@deprecated use {!of_iter} instead. *)
[@@ocaml.deprecated "use of_iter instead"]
val add_seq : t -> elt sequence -> t
(** @since 0.14
@deprecated use {!add_iter} instead. *)
[@@ocaml.deprecated "use add_iter instead"]
val to_seq : t -> elt sequence
(** [to_seq t] converts the set [t] to a [sequence] of the elements.
@deprecated use {!to_iter} instead. *)
[@@ocaml.deprecated "use to_iter instead"]
val add_list : t -> elt list -> t
(** @since 0.14 *)

View file

@ -7,7 +7,6 @@ open CCShims_
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a sequence = ('a -> unit) -> unit
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
(* standard implementations *)
@ -51,16 +50,6 @@ module type S = sig
@since 2.8
*)
val to_seq : t -> char sequence
(** Return the [sequence] of characters contained in the string.
@deprecated use {!to_iter} instead *)
[@@ocaml.deprecated "use to_iter or to_std_seq"]
val to_klist : t -> char klist
(** Return the [klist] of characters contained in the string.
@deprecated use {!to_std_seq} instead *)
[@@ocaml.deprecated "use to_std_seq"]
val to_list : t -> char list
(** Return the list of characters contained in the string. *)
@ -848,8 +837,6 @@ let of_gen g =
let to_iter s k = String.iter k s
let to_seq = to_iter
let rec _to_std_seq s i len () =
if len=0 then Seq.Nil
else Seq.Cons (s.[i], _to_std_seq s (i+1)(len-1))
@ -866,8 +853,6 @@ let of_std_seq seq =
Seq.iter (Buffer.add_char b) seq;
Buffer.contents b
let of_seq = of_iter
let rec _to_klist s i len () =
if len=0 then `Nil
else `Cons (s.[i], _to_klist s (i+1)(len-1))

View file

@ -5,11 +5,6 @@
(** {1 Basic String Utils} *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
@ -56,16 +51,6 @@ module type S = sig
@since 2.8
*)
val to_seq : t -> char sequence
(** Return the [sequence] of characters contained in the string.
@deprecated use {!to_iter} instead *)
[@@ocaml.deprecated "use to_iter or to_std_seq"]
val to_klist : t -> char klist
(** Return the [klist] of characters contained in the string.
@deprecated use {!to_std_seq} instead *)
[@@ocaml.deprecated "use to_std_seq"]
val to_list : t -> char list
(** Return the list of characters contained in the string. *)
@ -116,16 +101,6 @@ val of_std_seq : char Seq.t -> string
(** Convert a [sequence] of characters to a string.
@since 2.8 *)
val of_seq : char sequence -> string
(** Convert a [sequence] of characters to a string.
@deprecated use {!of_iter} instead *)
[@@ocaml.deprecated "use of_iter"]
val of_klist : char klist -> string
(** Convert a [klist] of characters to a string.
@deprecated use {!of_std_seq} instead *)
[@@ocaml.deprecated "use of_std_seq"]
val of_list : char list -> string
(** Convert a list of characters to a string. *)
@ -377,20 +352,12 @@ module Split : sig
val gen : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) gen
val iter : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) sequence
val iter : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) iter
(** @since 2.8 *)
val std_seq : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) Seq.t
(** @since 2.8 *)
val seq : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) sequence
(** deprecated, use {!iter} instead *)
[@@ocaml.deprecated "use iter"]
val klist : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) klist
(** deprecated, use {!std_seq} instead *)
[@@ocaml.deprecated "use std_seq"]
(** {4 Copying functions}
Those split functions actually copy the substrings, which can be
@ -400,20 +367,12 @@ module Split : sig
val gen_cpy : ?drop:drop_if_empty -> by:string -> string -> string gen
val iter_cpy : ?drop:drop_if_empty -> by:string -> string -> string sequence
val iter_cpy : ?drop:drop_if_empty -> by:string -> string -> string iter
(** @since 2.8 *)
val std_seq_cpy : ?drop:drop_if_empty -> by:string -> string -> string Seq.t
(** @since 2.8 *)
val seq_cpy : ?drop:drop_if_empty -> by:string -> string -> string sequence
(** deprecated, use {!iter_cpy} instead *)
[@@ocaml.deprecated "use iter_cpy"]
val klist_cpy : ?drop:drop_if_empty -> by:string -> string -> string klist
(** deprecated, use {!std_seq_cpy} instead *)
[@@ocaml.deprecated "use std_seq_cpy"]
val left : by:string -> string -> (string * string) option
(** Split on the first occurrence of [by] from the leftmost part of
the string.

View file

@ -3,10 +3,6 @@
(** {1 Basic String Utils} *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
@ -53,16 +49,6 @@ module type S = sig
@since 2.8
*)
val to_seq : t -> char sequence
(** Return the [sequence] of characters contained in the string.
@deprecated use {!to_iter} instead *)
[@@ocaml.deprecated "use to_iter or to_std_seq"]
val to_klist : t -> char klist
(** Return the [klist] of characters contained in the string.
@deprecated use {!to_std_seq} instead *)
[@@ocaml.deprecated "use to_std_seq"]
val to_list : t -> char list
(** Return the list of characters contained in the string. *)
@ -116,16 +102,6 @@ val of_std_seq : char Seq.t -> string
(** Convert a [sequence] of characters to a string.
@since 2.8 *)
val of_seq : char sequence -> string
(** Convert a [sequence] of characters to a string.
@deprecated use {!of_iter} instead *)
[@@ocaml.deprecated "use of_iter"]
val of_klist : char klist -> string
(** Convert a [klist] of characters to a string.
@deprecated use {!of_std_seq} instead *)
[@@ocaml.deprecated "use of_std_seq"]
val of_list : char list -> string
(** Convert a list of characters to a string. *)
@ -393,20 +369,12 @@ module Split : sig
val gen : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) gen
val iter : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) sequence
val iter : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) iter
(** @since 2.8 *)
val std_seq : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) Seq.t
(** @since 2.8 *)
val seq : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) sequence
(** deprecated, use {!iter} instead *)
[@@ocaml.deprecated "use iter"]
val klist : ?drop:drop_if_empty -> by:string -> string -> (string*int*int) klist
(** deprecated, use {!std_seq} instead *)
[@@ocaml.deprecated "use std_seq"]
(** {4 Copying functions}
Those split functions actually copy the substrings, which can be
@ -416,20 +384,12 @@ module Split : sig
val gen_cpy : ?drop:drop_if_empty -> by:string -> string -> string gen
val iter_cpy : ?drop:drop_if_empty -> by:string -> string -> string sequence
val iter_cpy : ?drop:drop_if_empty -> by:string -> string -> string iter
(** @since 2.8 *)
val std_seq_cpy : ?drop:drop_if_empty -> by:string -> string -> string Seq.t
(** @since 2.8 *)
val seq_cpy : ?drop:drop_if_empty -> by:string -> string -> string sequence
(** deprecated, use {!iter_cpy} instead *)
[@@ocaml.deprecated "use iter_cpy"]
val klist_cpy : ?drop:drop_if_empty -> by:string -> string -> string klist
(** deprecated, use {!std_seq_cpy} instead *)
[@@ocaml.deprecated "use std_seq_cpy"]
val left : by:(string [@keep_label]) -> string -> (string * string) option
(** Split on the first occurrence of [by] from the leftmost part of
the string.

View file

@ -10,7 +10,6 @@ open CCShims_
type uchar = Uchar.t
type 'a gen = unit -> 'a option
type 'a iter = ('a -> unit) -> unit
type 'a sequence = ('a -> unit) -> unit
let equal (a:string) b = Stdlib.(=) a b
let hash : string -> int = Hashtbl.hash
@ -125,8 +124,6 @@ let to_iter ?(idx=0) s : uchar iter =
done
with Stop -> ()
let to_seq = to_iter
let to_std_seq ?(idx=0) s : uchar Seq.t =
let rec loop st =
let r = ref None in
@ -226,8 +223,6 @@ let of_iter i : t =
i (code_to_string buf);
Buffer.contents buf
let of_seq = of_iter
let of_list l : t =
let buf = Buffer.create 32 in
List.iter (code_to_string buf) l;
@ -292,7 +287,7 @@ let of_string s = if is_valid s then Some s else None
with Exit ->
false
let uutf_to_seq s f =
let uutf_to_iter s f =
Uutf.String.fold_utf_8
(fun () _ -> function
| `Malformed _ -> f (Uchar.of_int 0xfffd)
@ -302,7 +297,7 @@ let of_string s = if is_valid s then Some s else None
(*$R
let s = of_string_exn "このため、" in
let s' = to_seq s |> of_seq in
let s' = to_iter s |> of_iter in
assert_equal ~cmp:equal ~printer s s'
*)
@ -315,7 +310,7 @@ let of_string s = if is_valid s then Some s else None
(*$QR & ~long_factor:10
Q.small_string (fun s ->
Q.assume (CCString.for_all (fun c -> Char.code c < 128) s);
s = (of_string_exn s |> to_seq |> of_seq |> to_string)
s = (of_string_exn s |> to_iter|> of_iter|> to_string)
)
*)
@ -338,7 +333,7 @@ let of_string s = if is_valid s then Some s else None
Q.string (fun s ->
Q.assume (is_valid s);
let s = of_string_exn s in
let s2 = s |> to_seq |> of_seq in
let s2 = s |> to_iter|> of_iter in
if s=s2 then true
else Q.Test.fail_reportf "s=%S, s2=%S" (to_string s)(to_string s2)
)
@ -369,8 +364,8 @@ let of_string s = if is_valid s then Some s else None
Q.small_string (fun s ->
Q.assume (is_valid s && uutf_is_valid s);
let pp s = Q.Print.(list pp_uchar) s in
let l_uutf = uutf_to_seq s |> Iter.to_list in
let l_co = of_string_exn s |> to_seq |> Iter.to_list in
let l_uutf = uutf_to_iter s |> Iter.to_list in
let l_co = of_string_exn s |> to_iter |> Iter.to_list in
if l_uutf = l_co then true
else Q.Test.fail_reportf "uutf: '%s', containers: '%s', is_valid %B, uutf_is_valid %B"
(pp l_uutf) (pp l_co) (is_valid s) (uutf_is_valid s)

View file

@ -19,10 +19,6 @@
type uchar = Uchar.t
type 'a gen = unit -> 'a option
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
@ -54,12 +50,6 @@ val to_iter : ?idx:int -> t -> uchar iter
@param idx offset where to start the decoding.
@since 2.8 *)
val to_seq : ?idx:int -> t -> uchar sequence
(** Iter of unicode codepoints.
@param idx offset where to start the decoding.
@deprecated use {!to_iter} or {!to_std_seq} instead *)
[@@ocaml.deprecated "use to_iter or to_std_seq instead"]
val to_std_seq : ?idx:int -> t -> uchar Seq.t
(** Iter of unicode codepoints.
@param idx offset where to start the decoding.
@ -94,14 +84,10 @@ val of_std_seq : uchar Seq.t -> t
(** Build a string from unicode codepoints
@since 2.8 *)
val of_iter : uchar sequence -> t
val of_iter : uchar iter -> t
(** Build a string from unicode codepoints
@since 2.8 *)
val of_seq : uchar sequence -> t
(** @deprecated use {!of_seq} or {!of_std_seq} instead *)
[@@ocaml.deprecated "use of_iter or of_std_seq instead"]
val of_gen : uchar gen -> t
val of_list : uchar list -> t

View file

@ -5,7 +5,6 @@
type rw = [`RW]
type ro = [`RO]
type 'a sequence = ('a -> unit) -> unit
type 'a iter = ('a -> unit) -> unit
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
type 'a gen = unit -> 'a option
@ -165,11 +164,11 @@ let clear v =
v.size <- 0
(*$R
let v = of_seq Iter.(1 -- 10) in
let v = of_iter Iter.(1 -- 10) in
OUnit.assert_equal 10 (size v);
clear v;
OUnit.assert_equal 0 (size v);
OUnit.assert_bool "empty_after_clear" (Iter.is_empty (to_seq v));
OUnit.assert_bool "empty_after_clear" (Iter.is_empty (to_iter v));
*)
let clear_and_reset v =
@ -177,7 +176,7 @@ let clear_and_reset v =
v.vec <- [||]
(* TODO*)
(*
(*
let v = create() in
let a = Weak.create 1 in
push v ("hello"^"world");
@ -232,8 +231,8 @@ let append a b =
*)
(*$R
let a = of_seq Iter.(1 -- 5) in
let b = of_seq Iter.(6 -- 10) in
let a = of_iter Iter.(1 -- 5) in
let b = of_iter Iter.(6 -- 10) in
append a b;
OUnit.assert_equal 10 (size a);
OUnit.assert_equal (Iter.to_array Iter.(1 -- 10)) (to_array a);
@ -327,8 +326,8 @@ let rec append_gen a b = match b() with
(Q.pair (gen Q.int) (gen Q.int)) (fun (v1,v2) ->
let l1 = to_list v1 in
append v1 v2;
Iter.to_list (to_seq v1) =
Iter.(to_list (append (of_list l1) (to_seq v2)))
Iter.to_list (to_iter v1) =
Iter.(to_list (append (of_list l1) (to_iter v2)))
)
*)
@ -418,7 +417,7 @@ let copy v = {
*)
(*$R
let v = of_seq Iter.(1 -- 100) in
let v = of_iter Iter.(1 -- 100) in
OUnit.assert_equal 100 (size v);
let v' = copy v in
OUnit.assert_equal 100 (size v');
@ -443,7 +442,7 @@ let shrink v n =
)
(*$R
let v = of_seq Iter.(1 -- 10) in
let v = of_iter Iter.(1 -- 10) in
shrink v 5;
OUnit.assert_equal [1;2;3;4;5] (to_list v);
*)
@ -620,8 +619,6 @@ let filter_in_place p v =
fill_with_junk_ v.vec !j (v.size - !j);
v.size <- !j
let filter' = filter_in_place
(*$T
let v = 1 -- 10 in filter_in_place (fun x->x<4) v; \
to_list v = [1;2;3]
@ -921,7 +918,7 @@ let of_std_seq ?(init=create ()) seq =
init
(*$T
of_seq Iter.(1 -- 10) |> to_list = CCList.(1 -- 10)
of_iter Iter.(1 -- 10) |> to_list = CCList.(1 -- 10)
*)
let to_iter v k = iter k v
@ -946,18 +943,12 @@ let to_std_seq_rev v =
in
aux (size v-1)
let of_seq = of_iter
let to_seq = to_iter
let to_seq_rev = to_iter_rev
let append_seq = append_iter
let flat_map_seq = flat_map_iter
(*$Q
Q.(list int) (fun l -> \
let v= of_list l in v |> to_seq_rev |> Iter.to_rev_list = l)
let v= of_list l in v |> to_iter_rev |> Iter.to_rev_list = l)
*)
let slice_seq v start len =
let slice_iter v start len =
assert (start >= 0 && len >= 0);
fun k ->
assert (start+len <= v.size);
@ -967,32 +958,13 @@ let slice_seq v start len =
done
(*$T
slice_seq (of_list [0;1;2;3;4]) 1 3 |> CCList.of_seq = [1;2;3]
slice_seq (of_list [0;1;2;3;4]) 1 4 |> CCList.of_seq = [1;2;3;4]
slice_seq (of_list [0;1;2;3;4]) 0 5 |> CCList.of_seq = [0;1;2;3;4]
slice_iter (of_list [0;1;2;3;4]) 1 3 |> CCList.of_iter = [1;2;3]
slice_iter (of_list [0;1;2;3;4]) 1 4 |> CCList.of_iter = [1;2;3;4]
slice_iter (of_list [0;1;2;3;4]) 0 5 |> CCList.of_iter = [0;1;2;3;4]
*)
let slice v = (v.vec, 0, v.size)
let fill_empty_slots_with v x : unit =
if capacity v > length v then (
Array.fill v.vec (length v) (capacity v - length v) x;
)
(* check it frees memory properly *)
(*$R
let s = "coucou" ^ "lol" in
let w = Weak.create 1 in
Weak.set w 0 (Some s);
let v = of_list ["a"; s] in
ignore (pop_exn v :string);
assert_equal ~printer:string_of_int 1 (length v);
assert_equal ~printer:CCFun.id "a" (get v 0);
fill_empty_slots_with v "";
Gc.major();
assert_equal None (Weak.get w 0);
*)
let (--) i j =
if i>j
then init (i-j+1) (fun k -> i-k)

View file

@ -18,10 +18,6 @@ type 'a ro_vector = ('a, ro) t
(** Alias for immutable vectors.
@since 0.15 *)
(* TODO: remove for 3.0 *)
type 'a sequence = ('a -> unit) -> unit
(** @deprecated use ['a iter] instead *)
type 'a iter = ('a -> unit) -> unit
(** Fast internal iterator.
@since 2.8 *)
@ -94,9 +90,6 @@ val append_std_seq : ('a, rw) t -> 'a Seq.t -> unit
(** Append content of iterator.
@since 2.8 *)
val append_seq : ('a, rw) t -> 'a sequence -> unit
(** Append content of sequence. *)
val append_list : ('a, rw) t -> 'a list -> unit
(** Append content of list.
@since 0.14 *)
@ -183,11 +176,6 @@ val filter_in_place : ('a -> bool) -> ('a, rw) t -> unit
(** Filter elements from the vector in place.
@since NEXT_RELEASE *)
val filter' : ('a -> bool) -> ('a, rw) t -> unit
(** Alias of {!filter_in_place}
@deprecated since NEXT_RELEASE, use {!filter_in_place} instead. *)
[@@ocaml.deprecated "use filter_in_place instead"]
val fold : ('b -> 'a -> 'b) -> 'b -> ('a,_) t -> 'b
(** Fold on elements of the vector *)
@ -219,21 +207,10 @@ val filter_map_in_place : ('a -> 'a option) -> ('a,_) t -> unit
val flat_map : ('a -> ('b,_) t) -> ('a,_) t -> ('b, 'mut) t
(** Map each element to a sub-vector. *)
val flat_map_iter : ('a -> 'b sequence) -> ('a,_) t -> ('b, 'mut) t
(** Like {!flat_map}, but using {!iter} for intermediate collections.
@since 2.8 *)
val flat_map_std_seq : ('a -> 'b Seq.t) -> ('a,_) t -> ('b, 'mut) t
(** Like {!flat_map}, but using [Seq] for intermediate collections.
@since 2.8 *)
val flat_map_seq : ('a -> 'b sequence) -> ('a,_) t -> ('b, 'mut) t
(** Like {!flat_map}, but using {!sequence} for
intermediate collections.
@deprecated use {!flat_map_iter} or {!flat_map_std_seq}
@since 0.14 *)
[@@ocaml.deprecated "use flat_map_iter or flat_map_std_seq"]
val flat_map_list : ('a -> 'b list) -> ('a,_) t -> ('b, 'mut) t
(** Like {!flat_map}, but using {!list} for
intermediate collections.
@ -311,15 +288,9 @@ val of_iter : ?init:('a,rw) t -> 'a iter -> ('a, rw) t
(** Convert an Iterator to a vector.
@since 2.8.1 *)
val of_seq : ?init:('a,rw) t -> 'a sequence -> ('a, rw) t
(** Convert an Iterator to a vector.
@deprecated use of_iter *)
[@@ocaml.deprecated "use of_iter. For the standard Seq, see {!of_std_seq}"]
val of_std_seq : ?init:('a,rw) t -> 'a Seq.t -> ('a, rw) t
(** Convert an Iterator to a vector.
@deprecated use of_iter *)
[@@ocaml.deprecated "use of_iter. For the standard Seq, see {!of_std_seq}"]
@since 2.8.1 *)
val to_iter : ('a,_) t -> 'a iter
(** Return a [iter] with the elements contained in the vector.
@ -343,32 +314,15 @@ val to_std_seq_rev : ('a,_) t -> 'a Seq.t
@since 2.8
*)
val to_seq : ('a,_) t -> 'a sequence
(** @deprecated use to_iter *)
[@@ocaml.deprecated "use to_iter. For the standard Seq, see {!to_std_seq}"]
val to_seq_rev : ('a, _) t -> 'a sequence
(** [to_seq_rev v] returns the sequence of elements of [v] in reverse order,
that is, the last elements of [v] are iterated on first.
@since 0.14
@deprecated use {!to_iter_rev} *)
[@@ocaml.deprecated "use to_iter_rev. For the standard Seq, see {!to_std_seq_rev}"]
val slice : ('a,rw) t -> ('a array * int * int)
(** Vector as an array slice. By doing it we expose the internal array, so
be careful!. *)
val slice_seq : ('a,_) t -> int -> int -> 'a sequence
val slice_iter : ('a,_) t -> int -> int -> 'a iter
(** [slice_seq v start len] is the sequence of elements from [v.(start)]
to [v.(start+len-1)]. *)
val fill_empty_slots_with : ('a, _) t -> 'a -> unit
(** [fill_empty_slots_with v x] puts [x] in the slots of [v]'s underlying
array that are not used (ie in the last [capacity v - length v] slots).
This is useful if you removed some elements from the vector and
@deprecated after 2.8, as the vector doesn't keep values alive anymore (see #279, #282, #283)
@since 2.4 *)
[@@ocaml.deprecated "not needed anymore, see #279,#282,#283"]
to [v.(start+len-1)].
@since NEXT_RELEASE
*)
val of_klist : ?init:('a, rw) t -> 'a klist -> ('a, rw) t
val to_klist : ('a,_) t -> 'a klist

View file

@ -39,6 +39,7 @@ module Parse = CCParse
module Random = CCRandom
module Ref = CCRef
module Result = CCResult
module Seq = CCSeq
module Set = CCSet
module String = CCString
module Vector = CCVector

View file

@ -16,7 +16,7 @@
(public_name containers)
(wrapped false)
(modules :standard \ mkshims)
(flags :standard :standard -warn-error -a+8 -safe-string -nolabels -open
(flags :standard :standard -warn-error -a+8 -w -32-67 -safe-string -nolabels -open
CCMonomorphic)
(ocamlopt_flags (:include ../flambda.flags))
(libraries seq containers.monomorphic))

View file

@ -549,8 +549,8 @@ let of_seq seq =
bv
(*$T
CCList.range 0 10 |> CCList.to_seq |> of_seq |> to_seq \
|> CCList.of_seq |> List.sort CCOrd.compare = CCList.range 0 10
CCList.range 0 10 |> CCList.to_iter |> of_seq |> to_seq \
|> CCList.of_iter |> List.sort CCOrd.compare = CCList.range 0 10
*)
let pp out bv =

View file

@ -603,7 +603,7 @@ module Make(Key : KEY)
(*$R
let m = M.of_list [1, 1; 2, 2; 5, 5] in
let m' = M.update 4
(function
~f:(function
| None -> Some 4
| Some _ -> Some 0
) m

View file

@ -562,7 +562,7 @@ let rec merge ~f t1 t2 : _ t =
(*$QR
Q.(let p = small_list (pair small_int unit) in pair p p) (fun (l1,l2) ->
let l1 = _list_uniq l1 and l2 = _list_uniq l2 in
equal Stdlib.(=)
equal ~eq:Stdlib.(=)
(union (fun _ v1 _ -> v1) (of_list l1) (of_list l2))
(merge ~f:merge_union (of_list l1) (of_list l2)))
*)
@ -570,14 +570,14 @@ let rec merge ~f t1 t2 : _ t =
(*$QR
Q.(let p = small_list (pair small_int unit) in pair p p) (fun (l1,l2) ->
let l1 = _list_uniq l1 and l2 = _list_uniq l2 in
equal Stdlib.(=)
equal ~eq:Stdlib.(=)
(inter (fun _ v1 _ -> v1) (of_list l1) (of_list l2))
(merge ~f:merge_inter (of_list l1) (of_list l2)))
*)
(** {2 Conversions} *)
type 'a sequence = ('a -> unit) -> unit
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
@ -600,14 +600,14 @@ let to_list t = fold (fun k v l -> (k,v) :: l) t []
of_list l |> cardinal = List.length l)
*)
let add_seq t seq =
let add_iter t iter =
let t = ref t in
seq (fun (k,v) -> t := add k v !t);
iter (fun (k,v) -> t := add k v !t);
!t
let of_seq seq = add_seq empty seq
let of_iter iter = add_iter empty iter
let to_seq t yield = iter (fun k v -> yield (k,v)) t
let to_iter t yield = iter (fun k v -> yield (k,v)) t
let keys t yield = iter (fun k _ -> yield k) t

View file

@ -82,7 +82,7 @@ val merge :
(** {2 Whole-collection operations} *)
type 'a sequence = ('a -> unit) -> unit
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
@ -92,15 +92,15 @@ val of_list : (int * 'a) list -> 'a t
val to_list : 'a t -> (int * 'a) list
val add_seq : 'a t -> (int * 'a) sequence -> 'a t
val add_iter : 'a t -> (int * 'a) iter -> 'a t
val of_seq : (int * 'a) sequence -> 'a t
val of_iter : (int * 'a) iter -> 'a t
val to_seq : 'a t -> (int * 'a) sequence
val to_iter : 'a t -> (int * 'a) iter
val keys : _ t -> int sequence
val keys : _ t -> int iter
val values : 'a t -> 'a sequence
val values : 'a t -> 'a iter
val add_gen : 'a t -> (int * 'a) gen -> 'a t
(** @since 0.13 *)

View file

@ -90,7 +90,7 @@ let default ~default l =
)
(*$=
[1] (default (return 1) empty |> to_list)
[1] (default ~default:(return 1) empty |> to_list)
*)
module Infix = struct

View file

@ -284,7 +284,7 @@ module MakeFromArray(A:Array.S) : S with module Array = A = struct
let b = Byte.create (max s_len 64) in \
Byte.blit_from b s 0 s_len; \
let b' = Byte.copy b in \
try Byte.iteri b (fun i c -> if Byte.get_front b' i <> c then raise Exit); true with Exit -> false)
try Byte.iteri b ~f:(fun i c -> if Byte.get_front b' i <> c then raise Exit); true with Exit -> false)
*)
(*$Q
@ -481,7 +481,7 @@ module MakeFromArray(A:Array.S) : S with module Array = A = struct
let s_len = Bytes.length s in \
let b = Byte.create (max s_len 64) in \
Byte.blit_from b s 0 s_len; \
try Byte.iteri b (fun i c -> if Byte.get_front b i <> c then raise Exit); \
try Byte.iteri b ~f:(fun i c -> if Byte.get_front b i <> c then raise Exit); \
true with Exit -> false)
*)

View file

@ -41,7 +41,7 @@
Q.(list op) (fun l -> let m = apply_ops l M.empty in M.balanced m)
*)
type 'a sequence = ('a -> unit) -> unit
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a printer = Format.formatter -> 'a -> unit
@ -149,11 +149,11 @@ module type S = sig
val to_list : 'a t -> (key * 'a) list
val add_seq : 'a t -> (key * 'a) sequence -> 'a t
val add_iter : 'a t -> (key * 'a) iter -> 'a t
val of_seq : (key * 'a) sequence -> 'a t
val of_iter : (key * 'a) iter -> 'a t
val to_seq : 'a t -> (key * 'a) sequence
val to_iter : 'a t -> (key * 'a) iter
val add_gen : 'a t -> (key * 'a) gen -> 'a t
@ -500,8 +500,8 @@ module MakeFull(K : KEY) : S with type key = K.t = struct
List.for_all (fun (k,v) ->
let l, v', r = M.split k m in
v' = Some v
&& (M.to_seq l |> Iter.for_all (fun (k',_) -> k' < k))
&& (M.to_seq r |> Iter.for_all (fun (k',_) -> k' > k))
&& (M.to_iter l |> Iter.for_all (fun (k',_) -> k' < k))
&& (M.to_iter r |> Iter.for_all (fun (k',_) -> k' > k))
&& M.balanced m
&& M.cardinal l + M.cardinal r + 1 = List.length lst
) lst)
@ -533,7 +533,7 @@ module MakeFull(K : KEY) : S with type key = K.t = struct
(*$R
let m1 = M.of_list [1, 1; 2, 2; 4, 4] in
let m2 = M.of_list [1, 1; 3, 3; 4, 4; 7, 7] in
let m = M.merge (fun k -> CCOpt.map2 (+)) m1 m2 in
let m = M.merge ~f:(fun k -> CCOpt.map2 (+)) m1 m2 in
assert_bool "balanced" (M.balanced m);
assert_equal
~cmp:(CCList.equal (CCPair.equal CCInt.equal CCInt.equal))
@ -546,7 +546,7 @@ module MakeFull(K : KEY) : S with type key = K.t = struct
Q.(let p = list (pair small_int small_int) in pair p p) (fun (l1, l2) ->
let l1 = _list_uniq l1 and l2 = _list_uniq l2 in
let m1 = M.of_list l1 and m2 = M.of_list l2 in
let m = M.merge (fun _ v1 v2 -> match v1 with
let m = M.merge ~f:(fun _ v1 v2 -> match v1 with
| None -> v2 | Some _ as r -> r) m1 m2 in
List.for_all (fun (k,v) -> M.get_exn k m = v) l1 &&
List.for_all (fun (k,v) -> M.mem k m1 || M.get_exn k m = v) l2)
@ -560,14 +560,14 @@ module MakeFull(K : KEY) : S with type key = K.t = struct
let to_list m = fold ~f:(fun acc k v -> (k,v) :: acc) ~x:[] m
let add_seq m seq =
let add_iter m seq =
let m = ref m in
seq (fun (k,v) -> m := add k v !m);
!m
let of_seq s = add_seq empty s
let of_iter s = add_iter empty s
let to_seq m yield = iter ~f:(fun k v -> yield (k,v)) m
let to_iter m yield = iter ~f:(fun k v -> yield (k,v)) m
let rec add_gen m g = match g() with
| None -> m

View file

@ -6,7 +6,7 @@
@since 0.13 *)
type 'a sequence = ('a -> unit) -> unit
type 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
type 'a printer = Format.formatter -> 'a -> unit
@ -114,11 +114,11 @@ module type S = sig
val to_list : 'a t -> (key * 'a) list
val add_seq : 'a t -> (key * 'a) sequence -> 'a t
val add_iter : 'a t -> (key * 'a) iter -> 'a t
val of_seq : (key * 'a) sequence -> 'a t
val of_iter : (key * 'a) iter -> 'a t
val to_seq : 'a t -> (key * 'a) sequence
val to_iter : 'a t -> (key * 'a) iter
val add_gen : 'a t -> (key * 'a) gen -> 'a t

View file

@ -4,7 +4,7 @@
(public_name containers-thread)
(wrapped false)
(optional)
(flags :standard -warn-error -a+8 -safe-string -open CCShims_)
(flags :standard -warn-error -a+8 -w -32 -safe-string -open CCShims_)
(ocamlopt_flags :standard (:include ../flambda.flags))
(libraries containers threads))