Currying

Currying

Currying (selten auch: Schönfinkeln) ist die Umwandlung einer Funktion mit mehreren Argumenten in eine Funktion mit einem Argument. Obwohl das Verfahren von Moses Schönfinkel und Gottlob Frege erfunden wurde, ist es nach Haskell Brooks Curry benannt.

Verfahren

Es sei eine Funktion gegeben, die n Argumente erfordert. Wird diese auf ein Argument angewendet, so konsumiert sie nur genau dieses und liefert als Funktionswert eine weitere Funktion, die noch n-1 Argumente verlangt. Die zurückgegebene Funktion wird anschließend auf alle weiteren Argumente angewendet.

In Typen ausgedrückt, handelt es sich um die Umrechnung einer Funktion f:A_1\times\ldots\times A_n\to B zu einer modifizierten Funktion f':A_1\to(A_2\to(\ldots(A_n\to B)\ldots)).

Beispiel

Ein Beispiel in Lambda-Notation soll das Verfahren verdeutlichen, wobei die Funktion konkret folgendermaßen definiert sei:


\lambda x\ y\ z\ .\ x\ y\ z

Die Funktion verlangt also 3 Argumente und gibt diese zurück. Die Definition ist äquivalent zu:


\lambda x.\lambda y.\lambda z\ .\ x\ y\ z

Bei der Anwendung der Funktion auf die Argumente a, b und c geschieht Folgendes:


\left(\lambda x.\lambda y.\lambda z\ .\ x\ y\ z\right)\ a\ b\ c\ \mathsf{-\ Die\ Anwendung}


\left(\lambda y.\lambda z\ .\ a\ y\ z\right)\ b\ c


\left(\lambda z\ .\ a\ b\ z\right)\ c

a\ b\ c\ \mathsf{-\ Resultat}

Nach erstmaliger Anwendung der Funktion auf a, b und c wird x im Funktionskörper durch das erste Argument a ersetzt. Das Resultat ist eine Funktion, die noch die Argumente y und z verlangt. Diese wird sofort auf b und c angewendet.

Anwendung

Currying wird überwiegend in Programmiersprachen und Kalkülen verwendet, in denen Funktionen nur ein einzelnes Argument erhalten dürfen. Dazu gehören beispielsweise ML, Unlambda und der Lambda-Kalkül und das nach Curry benannte Haskell. Viele dieser Sprachen bieten dem Programmierer allerdings syntaktische Möglichkeiten, dies zu verschleiern. Ein Beispiel hierfür ist die Äquivalenz der Funktionsdefinition im oben gezeigten Beispiel.


Wikimedia Foundation.

Игры ⚽ Поможем сделать НИР

Schlagen Sie auch in anderen Wörterbüchern nach:

  • Currying — This article is about the function transformation technique. For the general variety of spicy dishes, see Curry. In mathematics and computer science, currying is the technique of transforming a function that takes multiple arguments (or an n… …   Wikipedia

  • Currying — Curry Cur ry (k?r r?), v. t. [imp. & p. p. {Curried} ( r?d); p. pr. & vb. n. {Currying}.] [OE. curraien, curreien, OF. cunreer, correier, to prepare, arrange, furnish, curry (a horse), F. corroyer to curry (leather) (cf. OF. conrei, conroi, order …   The Collaborative International Dictionary of English

  • currying — noun The technique of transforming a function that takes multiple arguments into a function that takes a single argument (the first of the arguments to the original function) and returns a new function that takes the remainder of the arguments… …   Wiktionary

  • currying — cur·ry || kÊŒrɪ n. curry powder, seasoning which is made from a combination of tumeric and other spices (commonly used in East Indian dishes); food seasoned with curry v. brush down a horse; prepare leather; beat, hit; flavor with curry powder …   English contemporary dictionary

  • currying — currˈying noun • • • Main Entry: ↑curry …   Useful english dictionary

  • vaunt-currying — …   Useful english dictionary

  • Schönfinkeln — Currying (selten auch: Schönfinkeln) ist die Umwandlung einer Funktion mit mehreren Argumenten in mehrere Funktionen mit je einem Argument. Obwohl das Verfahren von Moses Schönfinkel und Gottlob Frege erfunden wurde, ist es ist nach Haskell… …   Deutsch Wikipedia

  • Currificación — Saltar a navegación, búsqueda En la ciencia de la computación, currificar, inventada por Moses Schönfinkel y Gottlob Frege, es la técnica que consiste en transformar una función que utiliza múltiples argumentos (o más específicamente una n tupla… …   Wikipedia Español

  • Anonymous function — In computing, an anonymous function is a function (or a subroutine) defined, and possibly called, without being bound to a name. In lambda calculus, all functions are anonymous. The Y combinator can be utilised in these circumstances to provide… …   Wikipedia

  • Function (mathematics) — f(x) redirects here. For the band, see f(x) (band). Graph of example function, In mathematics, a function associates one quantity, the a …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”