currying : Java Glossary

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

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/currying.html J:\mindprod\jgloss\currying.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.211]
You are visitor number 8,110.