In computer science, partial application refers to the process of fixing a number of arguments to a function, producing another function of smaller arity. Given a function, we might fix the first argument, producing a function of type. Evaluation of this function might be represented as. 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.
Motivation
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, then div with the parameter x fixed at 1 is another function: div1 = div = 1/y. This is the same as the function inv that returns the multiplicative inverse of its argument, defined by inv = 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.
Implementations
In languages such as ML, Haskell and F#, functions are defined in curried formby default. Supplying fewer than the total number of arguments is referred to as partial application. In languages with first-class functions one can define curry, uncurry and papply to perform currying and partial application explicitly. This might incur a greater run-time overhead due to the creation of additional closures, while Haskell can use more efficient techniques. Scala implements optional partial application with placeholder, e.g. returns an incrementing function. Scala also support multiple parameter lists as currying, e.g.. Clojure implements partial application using the partial function defined in its core library. The C++ standard library provides bind to return a function object that is the result of partial application of the given arguments to the given function. Alternatively, lambda expressions can be used: int f; auto f_partial = ; assert f; In Java, MethodHandle.bindTo partially applies a function to its first argument. In Raku, the method creates a new function with fewer parameters. The Pythonstandard 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.
Definitions
In the simply-typed lambda calculus with function and product types partial application, currying and uncurrying can be defined as: ; papply : × a) → = λ. λy. f ; curry : → = λf. λx. λy. f ; uncurry : → = λf. λ. f x y Note that currypapply = curry.