SUPPORT THE WORK

GetWiki

Partial application

ARTICLE SUBJECTS
aesthetics  →
being  →
complexity  →
database  →
enterprise  →
ethics  →
fiction  →
history  →
internet  →
knowledge  →
language  →
licensing  →
linux  →
logic  →
method  →
news  →
perception  →
philosophy  →
policy  →
purpose  →
religion  →
science  →
sociology  →
software  →
truth  →
unix  →
wiki  →
ARTICLE TYPES
essay  →
feed  →
help  →
system  →
wiki  →
ARTICLE ORIGINS
critical  →
discussion  →
forked  →
imported  →
original  →
Partial application
[ temporary import ]
please note:
- the content below is remote from Wikipedia
- it has been imported raw for GetWiki


"arguments of a function"
//-->{{Short description|In functional programming}}{{Distinguish|partial evaluation|partial function}}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_{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.

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) = x/y, then div with the parameter x fixed at 1 is another function: div1(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.

Implementations

In languages such as ML, Haskell and F#, functions are defined in curried form by 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.{{harvnb|Marlow|Peyton Jones|2004}}Scala implements optional partial application with placeholder, e.g. {{code|2=scala|1=def add(x: Int, y: Int) = {x+y}; add(1, _: Int)}} returns an incrementing function. Scala also supports multiple parameter lists as currying, e.g. {{code|2=scala|1=def add(x: Int)(y: Int) = {x+y}; add(1) _}}.Clojure implements partial application using the partial function defined in its core library.WEB, clojure/clojure, partial function,weblink 2020-07-18, GitHub, en, The C++ standard library provides bind(function, args..) to return a function object that is the result of partial application of the given arguments to the given function. Since C++20 the function bind_front(function, args...) is also provided which binds the first sizeof...(args) arguments of the function to the args. In contrast, bind allows binding any of the arguments of the function passed to it, not just the first ones. Alternatively, lambda expressions can be used: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.WEB,weblink MethodHandle (Java Platform SE 7), docs.oracle.com, en, 2018-09-12, 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.WEB,weblink Method assuming, docs.perl6.org, 2018-09-12, The Python standard library module functools includes the partial function, allowing positional and named argument bindings, returning a new function.WEB,weblink 10.2. functools — Higher-order functions and operations on callable objects — Python 3.7.0 documentation, docs.python.org, 2018-09-12, In XQuery, an argument placeholder (?) is used for each non-fixed argument in a partial function application.WEB,weblink XQuery 3.1: An XML Query Language, www.w3.org, EN, 2018-09-12,

Definitions

In the simply-typed lambda calculus with function and product types (λ→,×) partial application, currying and uncurrying can be defined as
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.

Mathematical formulation and examples

Partial application can be a useful way to define several useful notions in mathematics. Given sets X, Y and Z, and a function f: Xtimes Y rightarrow Z, one can define the function
f(,cdot, , -): Xrightarrow (Yrightarrow Z),
where (Yrightarrow Z) is the set of functions Yrightarrow Z. The image of xin X under this map is f(x, ,cdot,):Yrightarrow Z. This is the function which sends y in Y to f(x,y). There are often structures on X, Y, Z which mean that the image of f(,cdot, ,-) restricts to some subset of functions Yrightarrow Z, as illustrated in the following examples.

Group actions

A group action can be understood as a function * : Gtimes X rightarrow X. The partial evaluation rho: G rightarrow text{Sym}(X)subset (Xrightarrow X) restricts to the group of bijections from X to itself. The group action axioms further ensure rho is a group homomorphism.

Inner-products and canonical map to the dual

An inner-product on a vector space V over a field K is a map phi:Vtimes Vrightarrow K. The partial evaluation provides a canonical map to the dual vector space, phi(, cdot , ,-):Vrightarrow V^*subset (Vrightarrow K). If this is the inner-product of a Hilbert space, the Riesz representation theorem ensures this is an isomorphism.

Cross-products and the adjoint map for Lie algebras

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}timesmathbf{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}timesmathfrak{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.

See also

References

{{Reflist}}

Further reading

  • {{citation |author-link1=Simon Marlow |last1=Marlow |first1=Simon |author-link2=Simon Peyton Jones |first2=Simon |last2=Peyton Jones |date=2004 |url=http://research.microsoft.com/en-us/um/people/simonpj/papers/eval-apply/eval-apply-icfp.ps |title=Making a Fast Curry: Push/Enter vs. Eval/Apply for Higher-order Languages |work=ICFP '04 Proceedings of the ninth ACM SIGPLAN international conference on Functional programming}}
  • Benjamin C. Pierce et al. "Partial Application", {{Webarchive|url=https://web.archive.org/web/20160521182324weblink |date=2016-05-21 }} "Digression: Currying". {{Webarchive|url=https://web.archive.org/web/20160521182324weblink |date=2016-05-21 }} Software Foundations.

External links



- content above as imported from Wikipedia
- "Partial application" does not exist on GetWiki (yet)
- time: 3:03pm EDT - Sat, May 04 2024
[ this remote article is provided by Wikipedia ]
LATEST EDITS [ see all ]
GETWIKI 23 MAY 2022
GETWIKI 09 JUL 2019
Eastern Philosophy
History of Philosophy
GETWIKI 09 MAY 2016
GETWIKI 18 OCT 2015
M.R.M. Parrott
Biographies
GETWIKI 20 AUG 2014
CONNECT