| |
First consider mathematics.
Recall that the function composition of two or more functions uses the output of one function as the input of another.
For instance, f such that f(x)=cos(x2) is the composition of the cos function and the squaring function (here denoted by sq), which is usually written cos o sq.
Now consider Objective Caml:
let compose = function (g, f) -> (function x -> g (f (x)))
|
is a high-order function whose type is
('a -> 'b) * ('c -> 'a) -> ('c -> 'b)
|
Then
compose (cos, (function x -> x *. x))
|
represents the mathematical function cos o sq.
Its type is
Here is an example of applying it:
(compose (cos, (function x -> x *. x))) (-4.3)
|
|