remove type t2, breaking compat

This commit is contained in:
Simon Cruanes 2018-01-14 16:14:10 -06:00
parent 8e7d2bf77e
commit 204b47cb3f
3 changed files with 24 additions and 103 deletions

View file

@ -8,9 +8,6 @@ type 'a t = ('a -> unit) -> unit
type 'a sequence = 'a t type 'a sequence = 'a t
type (+'a, +'b) t2 = ('a -> 'b -> unit) -> unit
(** Sequence of pairs of values of type ['a] and ['b]. *)
(*$inject (*$inject
let pp_ilist = Q.Print.(list int) let pp_ilist = Q.Print.(list int)
*) *)
@ -515,9 +512,6 @@ let product outer inner k =
"c",0; "c", 1; "c", 2;] s "c",0; "c", 1; "c", 2;] s
*) *)
let product2 outer inner k =
outer (fun x -> inner (fun y -> k x y))
let rec diagonal_l l yield = match l with let rec diagonal_l l yield = match l with
| [] -> () | [] -> ()
| x::tail -> | x::tail ->
@ -946,36 +940,21 @@ let is_empty seq =
(** {2 Transform a sequence} *) (** {2 Transform a sequence} *)
let empty2 _ = ()
let is_empty2 seq2 =
try ignore (seq2 (fun _ _ -> raise ExitIsEmpty)); true
with ExitIsEmpty -> false
let length2 seq2 =
let r = ref 0 in
seq2 (fun _ _ -> incr r);
!r
let zip seq2 k = seq2 (fun x y -> k (x,y))
let unzip seq k = seq (fun (x,y) -> k x y)
let zip_i seq k = let zip_i seq k =
let r = ref 0 in let r = ref 0 in
seq (fun x -> let n = !r in incr r; k n x) seq (fun x -> let n = !r in incr r; k (n, x))
let fold2 f acc seq2 = let fold2 f acc seq2 =
let acc = ref acc in let acc = ref acc in
seq2 (fun x y -> acc := f !acc x y); seq2 (fun (x,y) -> acc := f !acc x y);
!acc !acc
let iter2 f seq2 = seq2 f let iter2 f seq2 = seq2 (fun (x,y) -> f x y)
let map2 f seq2 k = seq2 (fun x y -> k (f x y)) let map2 f seq2 k = seq2 (fun (x,y) -> k (f x y))
let map2_2 f g seq2 k = let map2_2 f g seq2 k =
seq2 (fun x y -> k (f x y) (g x y)) seq2 (fun (x,y) -> k (f x y, g x y))
(** {2 Basic data structures converters} *) (** {2 Basic data structures converters} *)
@ -1016,11 +995,6 @@ let of_array_i a k =
k (i, Array.unsafe_get a i) k (i, Array.unsafe_get a i)
done done
let of_array2 a k =
for i = 0 to Array.length a - 1 do
k i (Array.unsafe_get a i)
done
let array_slice a i j k = let array_slice a i j k =
assert (i >= 0 && j < Array.length a); assert (i >= 0 && j < Array.length a);
for idx = i to j do for idx = i to j do
@ -1047,7 +1021,7 @@ let hashtbl_add h seq =
(*$R (*$R
let h = (1 -- 5) let h = (1 -- 5)
|> zip_i |> zip_i
|> to_hashtbl2 in |> to_hashtbl in
(0 -- 4) (0 -- 4)
|> iter (fun i -> OUnit.assert_equal (i+1) (Hashtbl.find h i)); |> iter (fun i -> OUnit.assert_equal (i+1) (Hashtbl.find h i));
OUnit.assert_equal [0;1;2;3;4] (hashtbl_keys h |> sort ?cmp:None |> to_list); OUnit.assert_equal [0;1;2;3;4] (hashtbl_keys h |> sort ?cmp:None |> to_list);
@ -1061,15 +1035,8 @@ let to_hashtbl seq =
hashtbl_replace h seq; hashtbl_replace h seq;
h h
let to_hashtbl2 seq2 =
let h = Hashtbl.create 3 in
seq2 (fun k v -> Hashtbl.replace h k v);
h
let of_hashtbl h k = Hashtbl.iter (fun a b -> k (a, b)) h let of_hashtbl h k = Hashtbl.iter (fun a b -> k (a, b)) h
let of_hashtbl2 h k = Hashtbl.iter k h
let hashtbl_keys h k = Hashtbl.iter (fun a _ -> k a) h let hashtbl_keys h k = Hashtbl.iter (fun a _ -> k a) h
let hashtbl_values h k = Hashtbl.iter (fun _ b -> k b) h let hashtbl_values h k = Hashtbl.iter (fun _ b -> k b) h

View file

@ -36,8 +36,8 @@ type +'a t = ('a -> unit) -> unit
type +'a sequence = 'a t type +'a sequence = 'a t
type (+'a, +'b) t2 = ('a -> 'b -> unit) -> unit (** {b NOTE} Type [('a, 'b) t2 = ('a -> 'b -> unit) -> unit]
(** Sequence of pairs of values of type ['a] and ['b]. *) has been removed and subsumed by [('a * 'b) t] @since NEXT_RELEASE *)
type 'a equal = 'a -> 'a -> bool type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int type 'a hash = 'a -> int
@ -299,10 +299,6 @@ val diagonal : 'a t -> ('a * 'a) t
Iterates only once on the sequence, which must be finite. Iterates only once on the sequence, which must be finite.
@since 0.9 *) @since 0.9 *)
val product2 : 'a t -> 'b t -> ('a, 'b) t2
(** Binary version of {!product}. Same requirements.
@since 0.5 *)
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t
(** [join ~join_row a b] combines every element of [a] with every (** [join ~join_row a b] combines every element of [a] with every
element of [b] using [join_row]. If [join_row] returns None, then element of [b] using [join_row]. If [join_row] returns None, then
@ -470,28 +466,17 @@ val rev : 'a t -> 'a t
sequence to be finite. The result is persistent and does sequence to be finite. The result is persistent and does
not depend on the input being repeatable. *) not depend on the input being repeatable. *)
(** {2 Binary sequences} *) val zip_i : 'a t -> (int * 'a) t
(** Zip elements of the sequence with their index in the sequence.
Changed type @since NEXT_RELEASE to just give a sequence of pairs *)
val empty2 : ('a, 'b) t2 val fold2 : ('c -> 'a -> 'b -> 'c) -> 'c -> ('a * 'b) t -> 'c
val is_empty2 : (_, _) t2 -> bool val iter2 : ('a -> 'b -> unit) -> ('a * 'b) t -> unit
val length2 : (_, _) t2 -> int val map2 : ('a -> 'b -> 'c) -> ('a * 'b) t -> 'c t
val zip : ('a, 'b) t2 -> ('a * 'b) t val map2_2 : ('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a * 'b) t -> ('c * 'd) t
val unzip : ('a * 'b) t -> ('a, 'b) t2
val zip_i : 'a t -> (int, 'a) t2
(** Zip elements of the sequence with their index in the sequence *)
val fold2 : ('c -> 'a -> 'b -> 'c) -> 'c -> ('a, 'b) t2 -> 'c
val iter2 : ('a -> 'b -> unit) -> ('a, 'b) t2 -> unit
val map2 : ('a -> 'b -> 'c) -> ('a, 'b) t2 -> 'c t
val map2_2 : ('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a, 'b) t2 -> ('c, 'd) t2
(** [map2_2 f g seq2] maps each [x, y] of seq2 into [f x y, g x y] *) (** [map2_2 f g seq2] maps each [x, y] of seq2 into [f x y, g x y] *)
(** {2 Basic data structures converters} *) (** {2 Basic data structures converters} *)
@ -528,8 +513,6 @@ val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t val of_array_i : 'a array -> (int * 'a) t
(** Elements of the array, with their index *) (** Elements of the array, with their index *)
val of_array2 : 'a array -> (int, 'a) t2
val array_slice : 'a array -> int -> int -> 'a t val array_slice : 'a array -> int -> int -> 'a t
(** [array_slice a i j] Sequence of elements whose indexes range (** [array_slice a i j] Sequence of elements whose indexes range
from [i] to [j] *) from [i] to [j] *)
@ -567,15 +550,9 @@ val hashtbl_replace : ('a, 'b) Hashtbl.t -> ('a * 'b) t -> unit
val to_hashtbl : ('a * 'b) t -> ('a, 'b) Hashtbl.t val to_hashtbl : ('a * 'b) t -> ('a, 'b) Hashtbl.t
(** Build a hashtable from a sequence of key/value pairs *) (** Build a hashtable from a sequence of key/value pairs *)
val to_hashtbl2 : ('a, 'b) t2 -> ('a, 'b) Hashtbl.t
(** Build a hashtable from a sequence of key/value pairs *)
val of_hashtbl : ('a, 'b) Hashtbl.t -> ('a * 'b) t val of_hashtbl : ('a, 'b) Hashtbl.t -> ('a * 'b) t
(** Sequence of key/value pairs from the hashtable *) (** Sequence of key/value pairs from the hashtable *)
val of_hashtbl2 : ('a, 'b) Hashtbl.t -> ('a, 'b) t2
(** Sequence of key/value pairs from the hashtable *)
val hashtbl_keys : ('a, 'b) Hashtbl.t -> 'a t val hashtbl_keys : ('a, 'b) Hashtbl.t -> 'a t
val hashtbl_values : ('a, 'b) Hashtbl.t -> 'b t val hashtbl_values : ('a, 'b) Hashtbl.t -> 'b t

View file

@ -14,8 +14,8 @@ type +'a t = ('a -> unit) -> unit
type +'a sequence = 'a t type +'a sequence = 'a t
type (+'a, +'b) t2 = ('a -> 'b -> unit) -> unit (** {b NOTE} Type [('a, 'b) t2 = ('a -> 'b -> unit) -> unit]
(** Sequence of pairs of values of type ['a] and ['b]. *) has been removed and subsumed by [('a * 'b) t] @since NEXT_RELEASE *)
type 'a equal = 'a -> 'a -> bool type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int type 'a hash = 'a -> int
@ -271,10 +271,6 @@ val diagonal : 'a t -> ('a * 'a) t
Iterates only once on the sequence, which must be finite. Iterates only once on the sequence, which must be finite.
@since 0.9 *) @since 0.9 *)
val product2 : 'a t -> 'b t -> ('a, 'b) t2
(** Binary version of {!product}. Same requirements.
@since 0.5 *)
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t
(** [join ~join_row a b] combines every element of [a] with every (** [join ~join_row a b] combines every element of [a] with every
element of [b] using [join_row]. If [join_row] returns None, then element of [b] using [join_row]. If [join_row] returns None, then
@ -442,28 +438,17 @@ val rev : 'a t -> 'a t
sequence to be finite. The result is persistent and does sequence to be finite. The result is persistent and does
not depend on the input being repeatable. *) not depend on the input being repeatable. *)
(** {2 Binary sequences} *) val zip_i : 'a t -> (int * 'a) t
(** Zip elements of the sequence with their index in the sequence.
Changed type @since NEXT_RELEASE to just give a sequence of pairs *)
val empty2 : ('a, 'b) t2 val fold2 : f:('c -> 'a -> 'b -> 'c) -> init:'c -> ('a * 'b) t -> 'c
val is_empty2 : (_, _) t2 -> bool val iter2 : f:('a -> 'b -> unit) -> ('a * 'b) t -> unit
val length2 : (_, _) t2 -> int val map2 : f:('a -> 'b -> 'c) -> ('a * 'b) t -> 'c t
val zip : ('a, 'b) t2 -> ('a * 'b) t val map2_2 : f:('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a * 'b) t -> ('c * 'd) t
val unzip : ('a * 'b) t -> ('a, 'b) t2
val zip_i : 'a t -> (int, 'a) t2
(** Zip elements of the sequence with their index in the sequence *)
val fold2 : f:('c -> 'a -> 'b -> 'c) -> init:'c -> ('a, 'b) t2 -> 'c
val iter2 : f:('a -> 'b -> unit) -> ('a, 'b) t2 -> unit
val map2 : f:('a -> 'b -> 'c) -> ('a, 'b) t2 -> 'c t
val map2_2 : ('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a, 'b) t2 -> ('c, 'd) t2
(** [map2_2 f g seq2] maps each [x, y] of seq2 into [f x y, g x y] *) (** [map2_2 f g seq2] maps each [x, y] of seq2 into [f x y, g x y] *)
(** {2 Basic data structures converters} *) (** {2 Basic data structures converters} *)
@ -500,8 +485,6 @@ val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t val of_array_i : 'a array -> (int * 'a) t
(** Elements of the array, with their index *) (** Elements of the array, with their index *)
val of_array2 : 'a array -> (int, 'a) t2
val array_slice : 'a array -> int -> int -> 'a t val array_slice : 'a array -> int -> int -> 'a t
(** [array_slice a i j] Sequence of elements whose indexes range (** [array_slice a i j] Sequence of elements whose indexes range
from [i] to [j] *) from [i] to [j] *)
@ -539,15 +522,9 @@ val hashtbl_replace : ('a, 'b) Hashtbl.t -> ('a * 'b) t -> unit
val to_hashtbl : ('a * 'b) t -> ('a, 'b) Hashtbl.t val to_hashtbl : ('a * 'b) t -> ('a, 'b) Hashtbl.t
(** Build a hashtable from a sequence of key/value pairs *) (** Build a hashtable from a sequence of key/value pairs *)
val to_hashtbl2 : ('a, 'b) t2 -> ('a, 'b) Hashtbl.t
(** Build a hashtable from a sequence of key/value pairs *)
val of_hashtbl : ('a, 'b) Hashtbl.t -> ('a * 'b) t val of_hashtbl : ('a, 'b) Hashtbl.t -> ('a * 'b) t
(** Sequence of key/value pairs from the hashtable *) (** Sequence of key/value pairs from the hashtable *)
val of_hashtbl2 : ('a, 'b) Hashtbl.t -> ('a, 'b) t2
(** Sequence of key/value pairs from the hashtable *)
val hashtbl_keys : ('a, 'b) Hashtbl.t -> 'a t val hashtbl_keys : ('a, 'b) Hashtbl.t -> 'a t
val hashtbl_values : ('a, 'b) Hashtbl.t -> 'b t val hashtbl_values : ('a, 'b) Hashtbl.t -> 'b t