From hadley at rice.edu  Wed May  4 18:00:40 2011
From: hadley at rice.edu (Hadley Wickham)
Date: Wed, 4 May 2011 11:00:40 -0500
Subject: [Rd] Curry: proposed new functional programming, er, function.
In-Reply-To: <4DC16917.5090206@gmail.com>
References: <7098abec0711011200va3851o811f60bb100616ce@mail.gmail.com>
	<BANLkTi=jud5hhis5y-veQKZHzSYYoPqnBw@mail.gmail.com>
	<79F23BA7BB084E4FA01A8B93904CD02CF669FAA4C9@WIGGUMVS.win.ad.jhu.edu>
	<4DC16917.5090206@gmail.com>
Message-ID: <BANLkTikuy3OP8j5aymKuE_zmHtYLCkBZWg@mail.gmail.com>

>> # Use of Curry
>> adaptIntegrate(Curry(f, a=0.2), lower=0, upper=2)
>
> Two objections:
>
> 1. ?I don't see how that is preferable to
>
> adaptIntegrate(function(x) f(x, a=0.2), lower=0, upper=2)

It's less typing?

A more helpful use is when you have a list of functions:

    funs <- list(
      sum = sum,
      mean = mean,
      median = median
    )

with Curry function you can do :

    funs2 <- lapply(funs, Curry, na.rm = TRUE)

as opposed to

    funs2 <- list(
      sum = function(x, ...) sum(x, ..., na.rm = TRUE),
      mean = function(x, ...) mean(x, ..., na.rm = TRUE),
      median = function(x, ...) median(x, ..., na.rm = TRUE)
    )

> 2. ?There seems to be confusion about what currying means. ?The Wikipedia
> page <http://en.wikipedia.org/wiki/Currying> indicates that the function
> Curry() defined above is really doing "partial function application", not
> currying. ?I'm in no position to judge whether Byron got it right or
> Wikipedia did, but this suggests to me that the name "Curry" is
> inappropriate, since at least some people who know what currying is would
> not guess that it does what it does.

I'm not completely sure that discussion is canonical: wikipedia citing
a blog post does not a precedent make.  I agree the distinction is
sensible, but I think the partial function application sense of
currying is standard enough that it would cause much confusion. We are
not claiming that R has low-level currying, we're creating a function
to simulate a useful property of currying.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



[Rd] Curry: proposed new functional programming, er, function.
Hadley Wickham