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

Hadley Wickham hadley at rice.edu
Wed May 4 18:00:40 CEST 2011

>> # 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.


Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University

More information about the R-devel mailing list