jon.recoil.org

Module type Applicative.S3_kernel

Applicative operations. An applicative abstracts the notion of computations whose results can be combined. An 'a t represents a computation returning 'a.

This module type subsumes the other S*_kernel module types below. It is extended with infix operators in S* below.

type ('a, 'p, 'q) t

Applicative type. 'a is the result type. 'p and 'q are extra parameters unchanged by applicative operations.

val return : 'a 'p 'q. 'a -> ('a, 'p, 'q) t

Convert a value to a t.

val apply : 'a 'b 'p 'q. ('a -> 'b, 'p, 'q) t -> ('a, 'p, 'q) t -> ('b, 'p, 'q) t

Applies the functions in one t to the values in another. Well-behaved applicatives satisfy these "laws", using <*> as infix apply:

  • return Fn.id <*> t is equivalent to t
  • return Fn.compose <*> tf <*> tg <*> tx is equivalent to tf <*> (tg <*> tx)
  • return f <*> return x is equivalent to return (f x)
  • tf <*> return x is equivalent to return (fun f -> f x) <*> tf
val both : 'a 'b 'p 'q. ('a, 'p, 'q) t -> ('b, 'p, 'q) t -> ('a * 'b, 'p, 'q) t

Combines values in two ts as tuples. Using <*> as infix apply, equivalent to return (fun a b -> a, b) <*> ta <*> tb.

val map : 'a 'b 'p 'q. ('a, 'p, 'q) t -> f:('a -> 'b) -> ('b, 'p, 'q) t

Transforms the contents of a t. Using <*> as infix apply, equivalent to return f <*> t.

val map2 : 'a 'b 'c 'p 'q. ('a, 'p, 'q) t -> ('b, 'p, 'q) t -> f:('a -> 'b -> 'c) -> ('c, 'p, 'q) t

Combines the contents of two ts. Using <*> as infix apply, equivalent to return f <*> ta <*> tb.

val map3 : 'a 'b 'c 'd 'p 'q. ('a, 'p, 'q) t -> ('b, 'p, 'q) t -> ('c, 'p, 'q) t -> f:('a -> 'b -> 'c -> 'd) -> ('d, 'p, 'q) t

Combines the contents of three ts. Using <*> as infix apply, equivalent to return f <*> ta <*> tb <*> tc.

val all : 'a 'p 'q. ('a, 'p, 'q) t list -> ('a list, 'p, 'q) t

Combines a list of t.

val all_unit : 'p 'q. (unit, 'p, 'q) t list -> (unit, 'p, 'q) t

Combines a list of t whose contents are unimportant.