signature FN structure Fn : FN
The structure Fn defines basic generic combinators for functions that are useful for a wide range of programming tasks.
See also: General
Imported implicitly.
signature FN = sig val id : 'a -> 'a val const : 'a -> 'b -> 'a val apply : ('a -> 'b) * 'a -> 'b val o : ('b -> 'c) * ('a -> 'b) -> ('a -> 'c) val curry : ('a * 'b -> 'c) -> ('a -> 'b -> 'c) val uncurry : ('a -> 'b -> 'c) -> ('a * 'b -> 'c) val flip : ('a * 'b -> 'c) -> ('b * 'a -> 'c) val repeat : int -> ('a -> 'a) -> ('a -> 'a) val forever : ('a -> 'a) -> 'a -> 'b val iter : int -> (unit -> unit) -> unit end
id is the identity function. Thus, id a is equivalent to a.
const a is a constant function that always returns a. Thus, const a b is equivalent to a, except for side-effects.
apply(f,a) applies f to a. Thus, it is equivalent to f a.
f o g is the function composition of f and g. Thus, (f o g) a is equivalent to f(g a).
curry f transforms the binary function f into curried form. Thus, curry f a b is equivalent to f(a,b).
uncurry f transforms a curried function f into a binary function. Thus, uncurry f (a,b) is equivalent to f a b.
flip f switches the argument order of the binary function f. Thus, flip f (a,b) is equivalent to f(b,a).
repeat n f is the n-fold composition of f. Thus, repeat n f a is equivalent to f(...(f(a))...), where f occurs n times.
forever f a performs infinite repetition of the function f. Thus, forever f can be thought of as being equivalent to repeat ∞ f.
iter n f performs n times the application f(). Thus, iter n f is equivalent to (f();...;f()), with f occurring n times.