applicative and choice infix operators

This commit is contained in:
Simon Cruanes 2014-07-07 14:25:34 +02:00
parent 20f70e721f
commit abe4ba2aaf
2 changed files with 15 additions and 1 deletions

View file

@ -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

View file

@ -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