In mathematics and computer science, higher-order functions are functions which do at least one of the following:
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 are generally those with types containing more than one arrow. In functional programming, higher-order functions that return other functions are said to be curried.
The map function found in many functional programming languages is one example of a higher-order function. It takes a function f as an argument, and returns a new function which takes a list and applies the f to each element.
Other examples of higher-order functions include function composition, integration, and the constant-function function λx.λy.x.
Macros can also be used to achieve some of the effects of higher order functions. However, macros usually cannot avoid the problem of variable capture; they may also result in large amounts of duplicated code, which can be more difficult for a compiler to optimize. Macros are generally not strongly typed, although they may produce strongly typed code.
Objects in an object-oriented programming environment can be used as higher order functions – a method of an object acts in many ways like a function, and a method may take objects (containing methods) as arguments or return objects with methods. Unfortunately, objects often carry additional run-time overhead compared to pure functions. Language syntax can introduce additional difficulties; an object must be created to hold any parameters that are functions, and any resulting function must also have an associated object.
Functional programming | Mathematics | Lambda calculus
Funktion höherer Ordnung | 高階関数 | Функция высшего порядка | 高阶函数
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Higher-order function".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world