diff --git a/sequence.ml b/sequence.ml index b0f48ef..037ea1f 100644 --- a/sequence.ml +++ b/sequence.ml @@ -49,8 +49,8 @@ let from_fun f = let empty = fun k -> () let singleton x k = k x - let return x k = k x +let pure f k = k f (** Infinite sequence of the same element *) let repeat x = fun k -> while true do k x done @@ -701,6 +701,11 @@ module Infix = struct let (>>=) x f = flat_map f x let (>|=) x f = map f x + + let (<*>) funs args k = + funs (fun f -> args (fun x -> k (f x))) + + let (<+>) = append end include Infix diff --git a/sequence.mli b/sequence.mli index f5b3781..601bb59 100644 --- a/sequence.mli +++ b/sequence.mli @@ -79,6 +79,9 @@ val singleton : 'a -> 'a t val return : 'a -> 'a t (** Synonym to {!singleton} *) +val pure : 'a -> 'a t + (** Synonym to {!singleton} *) + val repeat : 'a -> 'a t (** Infinite sequence of the same element. You may want to look at {!take} if you iterate on it. *) @@ -442,6 +445,12 @@ module Infix : sig val (>|=) : 'a t -> ('a -> 'b) -> 'b t (** Infix version of {!map} *) + + val (<*>) : ('a -> 'b) t -> 'a t -> 'b t + (** Applicative operator (product+application) *) + + val (<+>) : 'a t -> 'a t -> 'a t + (** Concatenation of sequences *) end include module type of Infix