currying : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

currying
Currying is the incomplete application of arguments to a function. You won’t find it in Java but you will in functional languages such as Haskell and ML. For example, in Haskell we could write the function mult which takes two integers and returns their product:
mult :: Int -> Int -> Int
mult x y = x * y
Evaluating mult 2 6 would yield 12, as expected. To curry a function, one needs only to leave off one or more of the rightmost arguments. (Argument application must occur in a left-to-right order.) Evaluating mult 2 would yield the curried function (mult 2), which is a function of arity 1 (meaning it expects 1 argument). An argument can be applied to this function by evaluating (mult 2) 6, for instance. The inclusion of parentheses is important because it distinguishes the application of one argument to a curried function from the application of two arguments to a non-curried function.

This serves a similar function to default arguments in C++, or overloaded functions with fewer arguments than the basic function in Java.

Functions can be built of curried functions as

double = mult 2

This page is posted
on the web at:

http://mindprod.com/jgloss/currying.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\currying.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[18.226.166.106]
You are visitor number