From rvaradhan at jhmi.edu  Wed May  4 23:26:52 2011
From: rvaradhan at jhmi.edu (Ravi Varadhan)
Date: Wed, 4 May 2011 17:26:52 -0400
Subject: [Rd] Curry: proposed new functional programming, er, function.
In-Reply-To: <BANLkTikuy3OP8j5aymKuE_zmHtYLCkBZWg@mail.gmail.com>
References: <7098abec0711011200va3851o811f60bb100616ce@mail.gmail.com>
	<BANLkTi=jud5hhis5y-veQKZHzSYYoPqnBw@mail.gmail.com>
	<79F23BA7BB084E4FA01A8B93904CD02CF669FAA4C9@WIGGUMVS.win.ad.jhu.edu>
	<4DC16917.5090206@gmail.com>
	<BANLkTikuy3OP8j5aymKuE_zmHtYLCkBZWg@mail.gmail.com>
Message-ID: <79F23BA7BB084E4FA01A8B93904CD02CF669FAA4D7@WIGGUMVS.win.ad.jhu.edu>

Thanks, Hadley.  This (i.e., different ways to prepare curry) is quite instructive to me.

Best,
Ravi.

-------------------------------------------------------
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


-----Original Message-----
From: h.wickham at gmail.com [mailto:h.wickham at gmail.com] On Behalf Of Hadley Wickham
Sent: Wednesday, May 04, 2011 12:01 PM
To: Duncan Murdoch
Cc: Ravi Varadhan; Byron Ellis; R Development Mailing List
Subject: Re: [Rd] Curry: proposed new functional programming, er, function.

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