The term 'functor' has several common meanings: 1. Function object. In object-oriented languages, it is a feature that allows objects to be used as if they were ordinary functions. 2. A mathematical structure which deals with mappings between categories. This concept is a useful abstraction in some programming languages, notably Haskell, where it is implemented as a type class. 3. In OCaml, a module that takes another module as an argument.
In C++ function objects are often called functors.
Function objects can contain their own data values, thus allowing the programmer to emulate closures. Function object can use another function object as a parameter, and can return a structure which encapsulates functions and data specific to a set of inputs, which facilitates the generation of context specific code.
In OCaml, a functor is a module that can take other modules as arguments, producing a specialized module. Effectively a function mapping one module to another.
In Haskell, Functor
is a type class that corresponds to the mathematical structure from category theory, Functor, which deals with mappings between categories.
In Prolog, the root of a compound term functor(arg1, arg2, ..., argn)
is known as its "functor". Predicate clause's head is represented by a compound term whose functor is the predicate's name (e.g., father(F, S) :- ... .
).