Partial application

Uses your system voice; voice and rate in settings.

Snapshot

≈ 4 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In computer science, partial application (or partial function application) refers to the process of fixing a number of arguments of a function, producing another function of smaller arity. Given a function f \colon (X \times Y \times Z) \to N , we might fix (or 'bind') the first argument, producing a function of type \text{partial}(f) \colon (Y \times Z) \to N . Evaluation of this function might be represented as f_\text{partial}(2, 3) . Note that the result of partial function application in this case is a function that takes two arguments. Partial application is sometimes incorrectly called currying, which is a related, but distinct concept.

In computer science, partial application (or partial function application) refers to the process of fixing a number of arguments of a function, producing another function of smaller arity. Given a function f \colon (X \times Y \times Z) \to N , we might fix (or 'bind') the first argument, producing a function of type \text{partial}(f) \colon (Y \times Z) \to N . Evaluation of this function might be represented as f_\text{partial}(2, 3) . Note that the result of partial function application in this case is a function that takes two arguments. Partial application is sometimes incorrectly called currying, which is a related, but distinct concept. Intuitively, partial function application says "if you fix the first arguments of the function, you get a function of the remaining arguments". For example, if function div(x,y) = x/y, then div with the parameter x fixed at 1 is another function: div 1 (y) = div(1,y) = 1/y. This is the same as the function inv that returns the multiplicative inverse of its argument, defined by inv(y) = 1/y. The practical motivation for partial application is that very often the functions obtained by supplying some but not all of the arguments to a function are useful; for example, many languages have a function or operator similar to plus_one . Partial application makes it easy to define these functions, for example by creating a function that represents the addition operator with 1 bound as its first argument. int f(int a, int b); auto f_partial = [](int a) { return f(a, 123); }; assert(f_partial(456) == f(456, 123) ); In Java, MethodHandle.bindTo partially applies a function to its first argument. Alternatively, since Java 8, lambdas can be used: public static Function partialApply(BiFunction biFunc, A value) { return b -> biFunc.apply(value, b); } In Raku, the assuming method creates a new function with fewer parameters. The Python standard library module functools includes the partial function, allowing positional and named argument bindings, returning a new function. In XQuery, an argument placeholder ( ? ) is used for each non-fixed argument in a partial function application. papply : (((a × b) → c) × a) → (b → c) = λ(f, x). λy. f (x, y) curry : ((a × b) → c) → (a → (b → c)) = λf. λx. λy. f (x, y) uncurry : (a → (b → c)) → ((a × b) → c) = λf. λ(x, y). f x y Note that curry papply = curry . The partial application of the cross product \times on \mathbb{R}^3 is \times(\, \cdot \, , -): \mathbb{R}^3 \mapsto \text{End}(\mathbb{R}^3) . The image of the vector \mathbf{u} is a linear map T_\mathbf{u} such that T_\mathbf{u}(\mathbf{v}) = \mathbf{u}\times\mathbf{v} . The components of T_\mathbf{u} can be found to be (T_\mathbf{u})_{ij} = \epsilon_{ijk}u_k . This is closely related to the adjoint map for Lie algebras. Lie algebras are equipped with a bracket [\, \cdot \, , \, \cdot \,]:\mathfrak{g}\times\mathfrak{g}\rightarrow \mathfrak{g} . The partial application gives a map \text{ad}:\mathfrak{g}\rightarrow \text{End}(\mathfrak{g}) . The axioms for the bracket ensure this map is a homomorphism of Lie algebras.

Text derived from https://en.wikipedia.org/w/index.php?oldid=1338438031 under CC BY-SA 4.0; modifications have been made.