mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 11:15:32 -05:00
cleanup of Infix (removed some operators);
remove TypeClass
This commit is contained in:
parent
2d380a48ca
commit
93b6a18c41
3 changed files with 2 additions and 95 deletions
56
sequence.ml
56
sequence.ml
|
|
@ -630,69 +630,15 @@ let random_array a =
|
||||||
|
|
||||||
let random_list l = random_array (Array.of_list l)
|
let random_list l = random_array (Array.of_list l)
|
||||||
|
|
||||||
(** {2 Type-classes} *)
|
|
||||||
|
|
||||||
module TypeClass = struct
|
|
||||||
(** {3 Classes} *)
|
|
||||||
type ('a,'b) sequenceable = {
|
|
||||||
to_seq : 'b -> 'a t;
|
|
||||||
of_seq : 'a t -> 'b;
|
|
||||||
}
|
|
||||||
|
|
||||||
type ('a,'b) addable = {
|
|
||||||
empty : 'b;
|
|
||||||
add : 'b -> 'a -> 'b;
|
|
||||||
}
|
|
||||||
|
|
||||||
type 'a monoid = ('a,'a) addable
|
|
||||||
|
|
||||||
type ('a,'b) iterable = {
|
|
||||||
iter : ('a -> unit) -> 'b -> unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
(** {3 Instances} *)
|
|
||||||
|
|
||||||
let (sequenceable : ('a,'a t) sequenceable) = {
|
|
||||||
to_seq = (fun seq -> seq);
|
|
||||||
of_seq = (fun seq -> seq);
|
|
||||||
}
|
|
||||||
|
|
||||||
let (iterable : ('a, 'a t) iterable) = {
|
|
||||||
iter = (fun f seq -> iter f seq);
|
|
||||||
}
|
|
||||||
|
|
||||||
let (monoid : 'a t monoid) = {
|
|
||||||
empty = empty;
|
|
||||||
add = (fun s1 s2 -> append s1 s2);
|
|
||||||
}
|
|
||||||
|
|
||||||
(** {3 Conversions} *)
|
|
||||||
|
|
||||||
let of_iterable iterable x =
|
|
||||||
from_iter (fun k -> iterable.iter k x)
|
|
||||||
|
|
||||||
|
|
||||||
let to_addable addable seq =
|
|
||||||
fold addable.add addable.empty seq
|
|
||||||
end
|
|
||||||
|
|
||||||
(** {2 Infix functions} *)
|
(** {2 Infix functions} *)
|
||||||
|
|
||||||
module Infix = struct
|
module Infix = struct
|
||||||
let (--) i j = int_range ~start:i ~stop:j
|
let (--) i j = int_range ~start:i ~stop:j
|
||||||
|
|
||||||
let (--^) i j = int_range_dec ~start:i ~stop:j
|
let (--^) i j = int_range_dec ~start:i ~stop:j
|
||||||
|
|
||||||
let (|>) x f = f x
|
|
||||||
|
|
||||||
let (@@) a b = append a b
|
|
||||||
|
|
||||||
let (>>=) x f = flatMap f x
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let (--) = Infix.(--)
|
include Infix
|
||||||
|
|
||||||
let (--^) = Infix.(--^)
|
|
||||||
|
|
||||||
(** {2 Pretty printing of sequences} *)
|
(** {2 Pretty printing of sequences} *)
|
||||||
|
|
||||||
|
|
|
||||||
40
sequence.mli
40
sequence.mli
|
|
@ -381,38 +381,6 @@ val random_list : 'a list -> 'a t
|
||||||
(** Infinite sequence of random elements of the list. Basically the
|
(** Infinite sequence of random elements of the list. Basically the
|
||||||
same as {!random_array}. *)
|
same as {!random_array}. *)
|
||||||
|
|
||||||
(** {2 Type-classes} *)
|
|
||||||
|
|
||||||
module TypeClass : sig
|
|
||||||
(** {3 Classes} *)
|
|
||||||
type ('a,'b) sequenceable = {
|
|
||||||
to_seq : 'b -> 'a t;
|
|
||||||
of_seq : 'a t -> 'b;
|
|
||||||
}
|
|
||||||
|
|
||||||
type ('a,'b) addable = {
|
|
||||||
empty : 'b;
|
|
||||||
add : 'b -> 'a -> 'b;
|
|
||||||
}
|
|
||||||
|
|
||||||
type 'a monoid = ('a,'a) addable
|
|
||||||
|
|
||||||
type ('a,'b) iterable = {
|
|
||||||
iter : ('a -> unit) -> 'b -> unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
(** {3 Instances} *)
|
|
||||||
|
|
||||||
val sequenceable : ('a,'a t) sequenceable
|
|
||||||
val iterable : ('a,'a t) iterable
|
|
||||||
val monoid : 'a t monoid
|
|
||||||
|
|
||||||
(** {3 Conversions} *)
|
|
||||||
|
|
||||||
val of_iterable : ('a,'b) iterable -> 'b -> 'a t
|
|
||||||
val to_addable : ('a,'b) addable -> 'a t -> 'b
|
|
||||||
end
|
|
||||||
|
|
||||||
(** {2 Infix functions} *)
|
(** {2 Infix functions} *)
|
||||||
|
|
||||||
module Infix : sig
|
module Infix : sig
|
||||||
|
|
@ -424,15 +392,9 @@ module Infix : sig
|
||||||
(** [a --^ b] is the range of integers from [b] to [a], both included,
|
(** [a --^ b] is the range of integers from [b] to [a], both included,
|
||||||
in decreasing order (starts from [a]).
|
in decreasing order (starts from [a]).
|
||||||
It will therefore be empty if [a < b]. *)
|
It will therefore be empty if [a < b]. *)
|
||||||
|
|
||||||
val (|>) : 'a -> ('a -> 'b) -> 'b
|
|
||||||
|
|
||||||
val (@@) : 'a t -> 'a t -> 'a t
|
|
||||||
end
|
end
|
||||||
|
|
||||||
val (--) : int -> int -> int t
|
include module type of Infix
|
||||||
|
|
||||||
val (--^) : int -> int -> int t
|
|
||||||
|
|
||||||
(** {2 Pretty printing of sequences} *)
|
(** {2 Pretty printing of sequences} *)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ let test_concat () =
|
||||||
let s2 = (6 -- 10) in
|
let s2 = (6 -- 10) in
|
||||||
let l = [1;2;3;4;5;6;7;8;9;10] in
|
let l = [1;2;3;4;5;6;7;8;9;10] in
|
||||||
OUnit.assert_equal l (S.to_list (S.append s1 s2));
|
OUnit.assert_equal l (S.to_list (S.append s1 s2));
|
||||||
OUnit.assert_equal l (S.to_list (s1 @@ s2));
|
|
||||||
()
|
()
|
||||||
|
|
||||||
let test_fold () =
|
let test_fold () =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue