Function Application is not Currying
Jon Harrop
jon at ffconsultancy.com
Fri Jan 30 20:12:49 CET 2009
I had hoped someone else would correct you but they haven't. So...
Xah Lee wrote:
> Here are some examples of a function that returns a function as
> result, but is not currying.
>
> Mathematica example:
>
> f[n_]:=Function[n^#];
> f[7][2]
> (* returns 49 *)
>
> Emacs lisp example:
>
> (defmacro f (n) (list 'lambda (list 'x) (list 'expt n 'x) ) )
> (funcall (f 7) 2)
>
> Perl example:
>
> sub f {$n=$_[0]; sub { $n ** $_[0]} };
> print &{ f(7) } (2);
>
> Javascript example:
>
> function f(n) {return function (x) {return Math.pow(x,n);}; }
> alert (f(7) (2));
>
> However, the above are not languages that support currying,
That is incorrect. Mathematica, Lisp, Perl and Javascript all support
currying.
> which is a feature that Haskell & Ocaml has.
That is correct. Here is an OCaml equivalent:
let f =
fun n ->
fun m ->
n ** m
> To be more concrete, in the context of a given computer language, to
> say that it support curring, is to mean that the compiler understand
> the concept to certain degree. More to the point, the language is
> inherently able to take a function of more than one arg and
> deconstruct it to several functions of single arg.
That is incorrect. You only need a language with first-class functions.
I believe you are confusing the syntactic support in OCaml and Haskell for
something more. It simply allows you to rewrite the above as:
let f n m = n ** m
or:
let f = fun n m -> n ** n
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u
More information about the Python-list
mailing list