From 204b47cb3f2b3da12fb21b09636ebf860d1ca235 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sun, 14 Jan 2018 16:14:10 -0600 Subject: [PATCH] remove type `t2`, breaking compat --- src/Sequence.ml | 45 ++++++------------------------------------ src/Sequence.mli | 41 +++++++++----------------------------- src/SequenceLabels.mli | 41 +++++++++----------------------------- 3 files changed, 24 insertions(+), 103 deletions(-) diff --git a/src/Sequence.ml b/src/Sequence.ml index c60eff9..9a05f36 100644 --- a/src/Sequence.ml +++ b/src/Sequence.ml @@ -8,9 +8,6 @@ type 'a t = ('a -> unit) -> unit type 'a sequence = 'a t -type (+'a, +'b) t2 = ('a -> 'b -> unit) -> unit -(** Sequence of pairs of values of type ['a] and ['b]. *) - (*$inject let pp_ilist = Q.Print.(list int) *) @@ -515,9 +512,6 @@ let product outer inner k = "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 | [] -> () | x::tail -> @@ -946,36 +940,21 @@ let is_empty seq = (** {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 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 acc = ref acc in - seq2 (fun x y -> acc := f !acc x y); + seq2 (fun (x,y) -> acc := f !acc x y); !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 = - 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} *) @@ -1016,11 +995,6 @@ let of_array_i a k = k (i, Array.unsafe_get a i) 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 = assert (i >= 0 && j < Array.length a); for idx = i to j do @@ -1047,7 +1021,7 @@ let hashtbl_add h seq = (*$R let h = (1 -- 5) |> zip_i - |> to_hashtbl2 in + |> to_hashtbl in (0 -- 4) |> 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); @@ -1061,15 +1035,8 @@ let to_hashtbl seq = hashtbl_replace h seq; 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_hashtbl2 h k = Hashtbl.iter k 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 diff --git a/src/Sequence.mli b/src/Sequence.mli index 0d6fb79..f9000b9 100644 --- a/src/Sequence.mli +++ b/src/Sequence.mli @@ -36,8 +36,8 @@ type +'a t = ('a -> unit) -> unit type +'a sequence = 'a t -type (+'a, +'b) t2 = ('a -> 'b -> unit) -> unit -(** Sequence of pairs of values of type ['a] and ['b]. *) +(** {b NOTE} Type [('a, 'b) t2 = ('a -> 'b -> unit) -> unit] + has been removed and subsumed by [('a * 'b) t] @since NEXT_RELEASE *) type 'a equal = 'a -> 'a -> bool 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. @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 (** [join ~join_row a b] combines every element of [a] with every 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 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 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 +val map2_2 : ('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a * 'b) t -> ('c * 'd) t (** [map2_2 f g seq2] maps each [x, y] of seq2 into [f x y, g x y] *) (** {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 (** Elements of the array, with their index *) -val of_array2 : 'a array -> (int, 'a) t2 - val array_slice : 'a array -> int -> int -> 'a t (** [array_slice a i j] Sequence of elements whose indexes range 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 (** 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 (** 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_values : ('a, 'b) Hashtbl.t -> 'b t diff --git a/src/SequenceLabels.mli b/src/SequenceLabels.mli index 5b582e2..a928522 100644 --- a/src/SequenceLabels.mli +++ b/src/SequenceLabels.mli @@ -14,8 +14,8 @@ type +'a t = ('a -> unit) -> unit type +'a sequence = 'a t -type (+'a, +'b) t2 = ('a -> 'b -> unit) -> unit -(** Sequence of pairs of values of type ['a] and ['b]. *) +(** {b NOTE} Type [('a, 'b) t2 = ('a -> 'b -> unit) -> unit] + has been removed and subsumed by [('a * 'b) t] @since NEXT_RELEASE *) type 'a equal = 'a -> 'a -> bool 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. @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 (** [join ~join_row a b] combines every element of [a] with every 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 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 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 +val map2_2 : f:('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a * 'b) t -> ('c * 'd) t (** [map2_2 f g seq2] maps each [x, y] of seq2 into [f x y, g x y] *) (** {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 (** Elements of the array, with their index *) -val of_array2 : 'a array -> (int, 'a) t2 - val array_slice : 'a array -> int -> int -> 'a t (** [array_slice a i j] Sequence of elements whose indexes range 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 (** 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 (** 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_values : ('a, 'b) Hashtbl.t -> 'b t