CSC/ECE 517 Fall 2011/ch1 2a bi: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
== Introduction ==
== Introduction ==


Currying is the ability to take a function that accepts n parameters and generate from it one of more functions with some parameter values already filled in.  
Currying is a function transformation supported by some programming languages. It transforms a function that accepts n parameters and generates from it, one of more functions with some parameter values already filled in. These broken down functions can then be called in a chain to obtain a result equivalent to that obtained by calling the original function.
Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.


Currying has its origins in the mathematical study of functions. It was observed by Frege in 1893 that it suffices to restrict attention to functions of a single argument. For example, for any two parameter function f(x,y), there is a one parameter function f' such that f'(x) is a function that can be applied to y to give (f'(x))(y) = f (x,y). This corresponds to the well known fact that the sets (AxB -> C) and (A -> (B -> C)) are isomorphic, where "x" is cartesian product and "->" is function space.  It was independently re-discovered by Moses Schönfinkel [REFERENCE] and  by Haskell Curry [reference] and made it into the Haskell functional programming language as a primary feature.[]


Currying has its origins in the mathematical study of functions. It was observed by Frege in 1893 that it suffices to restrict attention to functions of a single argument. For example, for any two parameter function f(x,y), there is a one parameter function f' such that f'(x) is a function that can be applied to y to give (f'(x))(y) = f (x,y). This corresponds to the well known fact that the sets (AxB -> C) and (A -> (B -> C)) are isomorphic, where "x" is cartesian product and "->" is function space. In functional programming, function applicat
=== Definition ===
 
Given a function f of type , currying it makes a function . That is,  takes an argument of type  and returns a function of type . Uncurrying is the reverse transformation, and is most easily understood in terms of its right adjoint, apply.
Explanation, history
The → operator is often considered right-associative, so the curried function type  is often written as . Conversely, function application is considered to be left-associative, so that  is equivalent to .
 
=== Definition and Mathematical View ===


== Currying In Modern Languages  ==
== Currying In Modern Languages  ==


=== Currying In Ruby  ===
=== Currying In Ruby  ===
Implementation, proc objects


=== Currying In C  ===
=== Currying In C  ===
Line 22: Line 21:


== Usage ==
== Usage ==
 
Most programming languages such as C++ allow function parameters to be assigned to default values. However, the default values are restricted
== References ==
== References ==


== Links ==
== Links ==

Revision as of 16:57, 22 September 2011

Introduction

Currying is a function transformation supported by some programming languages. It transforms a function that accepts n parameters and generates from it, one of more functions with some parameter values already filled in. These broken down functions can then be called in a chain to obtain a result equivalent to that obtained by calling the original function.

Currying has its origins in the mathematical study of functions. It was observed by Frege in 1893 that it suffices to restrict attention to functions of a single argument. For example, for any two parameter function f(x,y), there is a one parameter function f' such that f'(x) is a function that can be applied to y to give (f'(x))(y) = f (x,y). This corresponds to the well known fact that the sets (AxB -> C) and (A -> (B -> C)) are isomorphic, where "x" is cartesian product and "->" is function space. It was independently re-discovered by Moses Schönfinkel [REFERENCE] and by Haskell Curry [reference] and made it into the Haskell functional programming language as a primary feature.[]

Definition

Given a function f of type , currying it makes a function . That is, takes an argument of type and returns a function of type . Uncurrying is the reverse transformation, and is most easily understood in terms of its right adjoint, apply. The → operator is often considered right-associative, so the curried function type is often written as . Conversely, function application is considered to be left-associative, so that is equivalent to .

Currying In Modern Languages

Currying In Ruby

Implementation, proc objects

Currying In C

Currying In Perl

Currying In Scala

Usage

Most programming languages such as C++ allow function parameters to be assigned to default values. However, the default values are restricted

References

Links