From: Xah Lee
Subject: Function Application is not Currying
Date: 
Message-ID: <99abb432-befd-4404-a166-84b6675b0f5d@i24g2000prf.googlegroups.com>
Function Application is not Currying

Xah Lee, 2009-01-28

In Jon Harrop's book Ocaml for Scientist at
http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html

It says:

    Currying

    A curried function is a function which returns a function as its
result.

LOL. That is incorrect.

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));

In the above, a function returns a function, and the result function
is applied to a value. They demonstrate 2 things:

    * The ability of the lang to have a function that returns a
function.
    * The ability to apply a value (of type function) to a value.

These, are 2 of the features that is part of often sloppily termed as
“function as first class citizens”.

However, the above are not languages that support currying, which is a
feature that Haskell & Ocaml has.

So what is Currying?

Wikipedia article Currying said it best:

    In computer science, currying, invented by Moses Schönfinkel and
Gottlob Frege, and independently by Haskell Curry,[1] is the technique
of transforming a function that takes multiple arguments (or more
accurately an n-tuple as argument) in such a way that it can be called
as a chain of functions each with a single argument.

Note how it says “is the technique of ...”.

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.

To say that function returning function is Currying, is a confusion of
fundamental concepts.

Mathematically, currying is the concept of deconstructing a function
of multiple parameters to a composition of several functions all of
arity 1.

I like Jon, because i consider majority of his argument and
perspective are more correct or sensible in his trollish spats in
newsgroup fighting with tech geekers. But he is really a asshole, and
take every chance to peddle his book. Every mother fucking
opponitunity, he injects random opinion into discussions about how
static typing or greatness of Microsoft, which paves a way for him to
post a link to his book on Ocaml/F# or “study” or “speed comparison”
of his site. He does this repeatedly and intentionally, about every
week for the past 2 or so years, and write in a way to provoke irate
responses. In the past 2 or 3 years, i have for 2 or so times without
his or anyone's solicitation, publically supported him in ugly
newsgroup fights (such as some serious sounding post that accuse him
of spamming or or some real life threats about network abuse).
However, in the past year as i have had some debates on language
issues with jon, i find Jon to be a complete asshole as far as his
newsgroup demeanor goes.

PS see also: A Mathematica Optimization Problem ( story of a thread
where Jon started a fight with me )

Perm url for this post:
• Function Application is not Currying
  http://xahlee.org/UnixResource_dir/writ/apply_func_examples.html

  Xah
∑ http://xahlee.org/

☄

From: alex23
Subject: Re: Function Application is not Currying
Date: 
Message-ID: <8837ddd8-1c53-4f13-b659-d75e0c0c04f7@r15g2000prd.googlegroups.com>
On Jan 29, 7:32 am, Xah Lee <······@gmail.com> wrote:
> But he is really a asshole, and
> take every chance to peddle his book.

As opposed to really being an asshole and peddling one's website at
every opportunity?
From: Russ P.
Subject: Re: Function Application is not Currying
Date: 
Message-ID: <5d34610d-5a70-4851-8e24-6a86230edaaf@n33g2000pri.googlegroups.com>
On Jan 28, 1:32 pm, Xah Lee <······@gmail.com> wrote:
> Function Application is not Currying
>
> Xah Lee, 2009-01-28
>
> In Jon Harrop's book Ocaml for Scientist athttp://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html
>
> It says:
>
>     Currying
>
>     A curried function is a function which returns a function as its
> result.
>
> LOL. That is incorrect.

What does that have to do with the price of bananas in Costa Rica?
From: Tim Greer
Subject: Re: Function Application is not Currying
Date: 
Message-ID: <0q9gl.109224$zJ2.519@newsfe23.iad>
Russ P. wrote:

> On Jan 28, 1:32 pm, Xah Lee <······@gmail.com> wrote:
>> Function Application is not Currying
>>
>> Xah Lee, 2009-01-28
>>
>> In Jon Harrop's book Ocaml for Scientist
>> athttp://www......./chapter1.html
>>
>> It says:
>>
>> Currying
>>
>> A curried function is a function which returns a function as its
>> result.
>>
>> LOL. That is incorrect.
> 
> What does that have to do with the price of bananas in Costa Rica?

Xah Lee does this stuff in 4 or 5 groups he's decided to post random
things to.  They rarely have any relevance or substance, just his
personal thoughts.  He liked to provoke arguing and tell everyone he's
a genius in his own mind.  It's best to just filter his posts out like
most of us have already done.  I don't know what group you're seeing
his post in, but he bugs us in the Perl group all the time, cross
posting things that have nothing to do with Perl (same with his cross
posts to Python, too). :-)
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
From: ···@netherlands.com
Subject: Re: Function Application is not Currying
Date: 
Message-ID: <7lp1o4dhnesn9uflq1nv1hrui4ke0mpd9d@4ax.com>
On Wed, 28 Jan 2009 13:32:29 -0800 (PST), Xah Lee <······@gmail.com> wrote:

>Function Application is not Currying
>
>Xah Lee, 2009-01-28
>
>In Jon Harrop's book Ocaml for Scientist at
>http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html
>
>It says:
>
>    Currying
>
>    A curried function is a function which returns a function as its
>result.
>
Curry, is that like chicken soup or some Indian mash?

Why ? How about returning an index number into an array of function pointers
as handlers from packet data?

Oh, thats network communications.

sln
From: Slobodan Blazeski
Subject: Re: Function Application is not Currying
Date: 
Message-ID: <a870f5e1-545c-4fa8-98b5-afa38e158bdc@y23g2000pre.googlegroups.com>
On Jan 28, 10:32 pm, Xah Lee <······@gmail.com> wrote:
> Function Application is not Currying
>
> Xah Lee, 2009-01-28
>
> In Jon Harrop's book Ocaml for Scientist athttp://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html
>
> It says:
>
>     Currying
>
>     A curried function is a function which returns a function as its
> result.
>
> LOL. That is incorrect.

Good catch Xah. Currying in pseudolisp
(defun add (x y) (+ x y))
(add 2 3)
-> 5
(apply (add 2) '(3))
(add 2) ; since argument is missing it returns a function that adds
its argument to 2
5
Not currying:
(defun foo (x)
  (if (oddp x) #'oddp #'evenp))

http://www.engr.uconn.edu/~jeffm/Papers/curry.html

cheers
bobi
From: William James
Subject: Re: Function Application is not Currying
Date: 
Message-ID: <go0c070lpc@enews5.newsguy.com>
Slobodan Blazeski wrote:

> 
> Good catch Xah. Currying in pseudolisp
> (defun add (x y) (+ x y))
> (add 2 3)
> -> 5
> (apply (add 2) '(3))
> (add 2) ; since argument is missing it returns a function that adds
> its argument to 2
> 5

Clojure:


user=> (defn avg [a b] (/ (+ a b) 2.0))
#'user/avg
user=> (avg 6 7)
6.5
user=> (def avg-with-6 (partial avg 6))
#'user/avg-with-6
user=> (avg-with-6 7)
6.5
From: Kaz Kylheku
Subject: Re: Function Application is not Currying
Date: 
Message-ID: <20090203171740.143@gmail.com>
On 2009-01-28, Xah Lee <······@gmail.com> wrote:
> Function Application is not Currying

That's correct, Xah. Currying is a special case of function application. 
A currying function is applied to some other function, and returns function
that has fewer arguments.

In some languages, you don't see the currying function. It's invisibly
performed whenever you forget an argument. Hit a three argument function with
only two arguments, and you don't get a nice ``insufficient arguments in
function call'' error, but the call is diverted to the currying function, which
gives you back a function of one argument, which you can then call with the
missing argument to compute the original function.

> Xah Lee, 2009-01-28
>
> In Jon Harrop's book Ocaml for Scientist at
> http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html

Figures you'd be reading this. Learning anything?

> It says:
>
>     Currying
>
>     A curried function is a function which returns a function as its
> result.
>
> LOL. That is incorrect.

Yawn. Say it isn't so.
From: Jon Harrop
Subject: Re: Function Application is not Currying
Date: 
Message-ID: <4uedncuZN9ixzR7UnZ2dnUVZ8rKdnZ2d@posted.plusnet>
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
From: Tim Greer
Subject: Re: Function Application is not Currying
Date: 
Message-ID: <RtIgl.1787$_N1.1474@newsfe01.iad>
Jon Harrop wrote:

> I had hoped someone else would correct you but they haven't. So...

The lack of replies aren't about anyone correcting him or not, it's that
the guy just posts anything he can to spamvertize his site and tell
everyone how brilliant he thinks he is.  It's just a method he uses to
try and feel important and also get people to his site (and for the
search engines to rank it higher).  He's a known troll and spammer in a
lot of groups due to this.  The guy rarely has anything relevant to the
groups he posts to.  Most people I know of have come to just filter out
his posts.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
From: J�rgen Exner
Subject: Re: Function Application is not Currying
Date: 
Message-ID: <a557o4lrjtaua10d7lsblvcpn6pdb2t4d5@4ax.com>
Jon Harrop <···@ffconsultancy.com> wrote:
>I had hoped someone else would correct you but they haven't. So...

That is because ...

>Xah Lee wrote:

... everyone with more than 5 cents of brain has killfiled him a long
time ago.

jue