In mathematics and computer science, a higher-order function (also functional, functional form or functor) is a function that does at least one of the following:
All other functions are first-order functions. In mathematics higher-order functions are also termed operators or functionals. The differential operator in calculus is a common example, since it maps a function to its derivative, also a function.
In the untyped lambda calculus, all functions are higher-order; in a typed lambda calculus, from which most functional programming languages are derived, higher-order functions that take one function as argument are values with types of the form .
The examples are not intended to compare and contrast programming languages, but to serve as examples of higher-order function syntax
In the following examples, the higher-order function twice
takes a function, and applies the function to some value twice. If twice
has to be applied several times for the same f
it preferably should return a function rather than a value. This is in line with the "don't repeat yourself" principle.