Currying is not functional programming, and overloading is not specific to object-oriented programming.
"Currying" is the use of functions for which you can pass fewer arguments than you need to get the function of the remaining arguments. those. if we have a plus function that takes two integer arguments and returns their sum, we can pass the single argument 1 to plus , and the result is a function to add 1 to things.
In Haskellish syntax (using adjacency function):
plusOne = plusCurried 1 three = plusOne 2 four = plusCurried 2 2 five = plusUncurried 2 3
In the undefined Cish syntax (using a function in parentheses):
plusOne = plusCurried(1) three = plusOne(2) four = plusCurried(2)(2) five = plusUncurried(2, 3)
In both examples, you can see that plusCurried is called with only one argument, and the result is something that can be bound to a variable, and then called with another argument. The reason you think of currying as a concept of functional programming is because it is most often used in functional languages โโwhose syntax has an adjacency application, because currying becomes very natural in this syntax. The plusCurried and plusUncurried to define four and five in the Haskellish syntax to become completely indistinguishable, so that you can simply completely execute all functions always (i.e. each function is a function with exactly one argument, only some of them will return other functions which can then be applied to more arguments). Whereas in Cish syntax using argument lists in parentheses, the definitions of four and five look completely different, so you need to distinguish between plusCurried and plusUncurried . In addition, the imperative languages โโthat led to today's object-oriented languages โโ(and some of the modern object-oriented languages) have never been able to associate functions with variables or pass them to other functions (this is known as first-class functions), and without this object there is nothing actually done with a curried function other than calling it on all arguments, and therefore it makes no sense to have them.
The term currying also refers to the process of converting a function from multiple arguments into one, which takes one argument and returns another function (which takes one argument and can return another function that ...), and "unurrying" can refer to the process of the inverse transformation.
Overloading is a completely unrelated concept. Overloading a name means providing several definitions with different characteristics (argument types, number of arguments, return type, etc.) and compiler resolution, the definition of which is implied by a certain kind of name in the context in which it appears.
A pretty obvious example of this is that we can define plus to add integers, but also use the same plus name to add floating point numbers, and we could potentially use it to concatenate strings, arrays, lists, etc. .d., or to add vectors or matrices. They all have very different implementations that have nothing to do with each other with respect to the language implementation, but we just got the same name. Then the compiler is responsible for finding out that plus stringA stringB should call the string plus (and return the string), and plus intX intY should call the integer plus (and return the integer).
Again, there is no inherent reason why this concept is an OO concept and not a functional programming concept. It just happened that it is quite natural in the statically typed object-oriented languages โโthat were developed; if you already allow which method to call the object on which the method is called, then this is a slight stretch to provide a more general overload. Completely ad-hoc overloading (where you do nothing more than specify the same name several times and trust the compiler to figure it out) doesn't work so well in languages โโwith first-class functions, because when you pass an overloaded name as a function itself , you donโt have a call context to help you determine which definition is intended (and programmers can get confused if what they really wanted was to pass all overloaded definitions). Haskell developed class classes as a more basic way to use overloading; they effectively allow the simultaneous transfer of all overloaded definitions, and also allow the type system to express types similar to "any type for which the functions f and g defined".
In short:
- currying and overloading are completely unrelated
- currying is applying functions to fewer arguments than it takes to get the function of the remaining arguments
- overloading is the provision of several definitions for the same name and the compiler choosing which definition is used each time the name is used.
- Neither currying nor overloading is specific to either functional programming or object-oriented programming; they seem simply more common in historical languages โโof one kind or another because of how languages โโevolved, which makes them more useful or more obvious in one language.