tuples and freeze dried function args

Bill Baxter dnewsgroup at billbaxter.com
Fri Feb 23 10:50:01 PST 2007


Kevin Bealer wrote:
> You can.  I do this in the futurism library, see here:
> 
> http://www.dsource.org/projects/futurism/browser/trunk/futurism/future.d
> 
> The function make_future and the class template Future do this; the make_future
> builds a future object which stores a delegate and its arguments.
> 
> Later, the program runs the function from these arguments.  There's a lot of other
> code in that file... I think you can find a simpler example at the bottom of this
> page:
> 
> http://www.digitalmars.com/d/tuple.html

> 'Functional' programming languages call this 'currying'.

Actually they call it "partial function application"

Currying is something else often mistaken for partial evaluation.

Currying is treating a function of N args that returns Ret
     func: (Arg1,Arg2,Arg3) -> Ret
as a function that does partial evaluation "to the max"
     func: Arg1 -> (Arg2 -> (Arg3 -> Ret))
That's a
    function that takes an Arg1 and returns
     (a function that takes an Arg2 and returns
        (a function that takes an Arg3 and returns a Ret))

So the call  func a b c  is treated as (((func a) b ) c) with currying.

In ML for instance, all functions are curried by default (but you can 
sort of override the behavior by declaring your function to take a tuple 
as a single argument).

Python has a partial application library that was originally called 
'curry' until the functional folks shot it down as a misnomer.  Now it's 
called 'partial'.
http://www.python.org/dev/peps/pep-0309/

--bb


More information about the Digitalmars-d-learn mailing list