Xah Lee, 2007-08
Dr Jon D Harrop wrote:
It is probably worth noting that currying is comparatively uncommon in both Lisp and Mathematica. The difference between the syntaxes is fairly small: ((f a) b) Lisp f[a][b] Mathematica f a b ML
There are few things i like to say about currying, and your comment.
* * *
I don't like the term “currying”. It smacks of academic mumbo jumbo. The primary fuel of its use among programers, is its obscurism. It makes the users of the term looks bigger then than they are. (not accusing you in anyway though).
As you know, there's the concept of turning a function with multiple parameters into a function with fewer parameters. This concept as a theory, and in particular as a actual implementation of it in a computer language as a feature, needs a name. And, the term “currying” has been adopted. (the particular reason for the word, as we know, is from the mathematician Haskell Curry).
If we were to make a general judgement on the naming of scientific/technical concepts (as a criticism about terminology), then, i think terms based on people's names are not to be preferred. (primarily because it imparts no information about what it means, secondarily because often it has nothing to do with the person (i.e. the named is often not the primary contributor of the theory/concept although in many cases it is meant to be and is)) Further, the quality of terminology has critical consequence, in education, efficiency of communication, and in how something is perceived.
(Richard Stallman has popularly made this point clear for non-scientific terms, mostly regarding Linux and his ideology about software in society (e.g. GNU/Linux, “Intellectual Property”, “Content Management System”/“Website Revision System”, “digital right management”/“ digital restrictions management” ... etc. (however, himself, in my opinion, have hijacked terms intentionally or unintentionally for his gain (e.g. Free, Hacker (anyone who is gonna write to me about the terms “Free” or “Hacker” automatically gets a moronic tech geeker moniker in my mind, unless, you have a Ph D in English or philosophy or human animal ethology or history or similar fields)))))
* * *
Now, in the above, i expressed a few things:
But actually, i wanted to speak about another issue, and that is: how the term Currying is often used by high-powered tech geekers (such as the lispers and functional programers) to simply mean applying a function that is returned by a function, and this subtle but different meaning, generates confusion. For example, in the following:
((f a) b) Lisp f[a][b] Mathematica f a b ML
Are they Currying? or are they just applying a return value of a function?
The significance of the term “currying”, usually lies in the context of language design. In particular, the feature of language being able to decomposing a function into one or more functions each with fewer parameters.
So, in Mathematica, form like this f[a][b] isn't currying in anyway, since the language does not have the notion of decomposing a function into functions with less arity. “f[a][b]” here is simply applying the value of f[a] to b.
Similarly, “((f a) b)” in lisp isn't currying in anyway.
* * *
In Mathematica, forms like f[a][b] or f[a1,a2,...][b1,b2,...]... etc are actually used often. As a example of a buildin function, most notable one is the function named “Derivative”. It is idiom, and is used in just about every sufficiantly large body of code, and described in just about all Mathematica programing text books.
In math, often a function has a subscript to indicate its particular family, level, class, or type. For example, Derivative[n] returns a function that returns the nth derivative of its argument. (So, it can be used like this: (Derivative[n])[f] or simply Derivative[n][f], to mean the nth derivative of f.)
Such a form can be defined using pattern matching, for example:
f[a_][b_] := a+b
Or without pattern matching:
f[a_][b_] := Function[a+b]
In either case, f[x] is meaningless (it is not defined and evaluates to itself).
However, often, in such a form, the programer (or mathematicians using the language) considers f to be a function of some index/type/class/domain, that returns a function. So, they want f[x] to return function. In this case, f can be defined using pattern matching, or not using pattern matching. Example:
f[x_]:= a+x; (*using pattern matching*) f=Function[x,a+x] (*without using pattern matching*)
In all 4 cases above, f[a][b] evaluates to a+b.
In the over one thousand pages of the Mathematica Book (its official manual), covering hundreds of advanced math functions and computations, one will find no mentioning of Currying or its concept whatsoever. (and this is in supreme contrast to the common programer and academics obfuscation and elitism of throwing out lambdas, currying, liiinda-meryer types, garbage collection, tail-recursion, and other shit.)
* * *
(Note in wikipedia: Currying, it defines currying as: «In computer science, currying or Schönfinkelisation[1] is the technique of transforming a function that takes multiple arguments into a function that takes a single argument (the other arguments having been specified by the curry).» Note how it says it is a “technique”.)
For examples of functions that return fuction and applying the result to a value, in 4 different languages that does not support currying, see: Function Application is not Currying
Related essays: