Function Currying
David Medlock
noone at nowhere.com
Wed Nov 15 18:38:12 PST 2006
Bill Baxter wrote:
> David Medlock wrote:
>
>> David Medlock wrote:
>>
>>>
>>> Nice walter.
>>>
>>> Its too bad though that inner function delegates don't live past the
>>> stack frame or this wouldn't really be necessary..hehe.
>>>
>>> -DavidM
>>
>>
>> Oh yes I will add another plug for a great book which explains
>> currying in the context of functions as well as programs:
>>
>> http://www.dina.dk/~sestoft/pebook/
>>
>>
>
> Oh yeh... that's the reason I had "partial evaluation" on the brain when
> I should have been saying "partial application". I looked over that
> link the last time you posted it, too.
>
> From what I gather from that web page and a quick google for "partial
> evaluation", it is a much more advanced beast than partial function
> application. In partial evaluation you'd take something like
> triple_integral(fx,fy,fz) that integrates over three variables, and your
> partial evaluation usage would be:
>
> single_integral = partial_eval(triple_integral, gx, gy);
> answer = single_integral(gz);
>
> Looks just like partial application, except in partial evaluation, the
> first two variables would actually be precomputed (integrated out) to
> create a new function that really did not require gx and gy to perform
> its computation.
>
> Is that the way you understand it, too, David?
>
> If so then there ain't no simple 1-page template that's going to be able
> to do that for the general case. :-) But it would be mighty cool if
> there were.
>
> --bb
I guess it depends on whether you wish to do it at runtime or compile time.
The point of the book( speaking here of Chapter 4, I haven't fully
digested all of it) is that you can take a function which simply
computes a value and slowly degenerate it into a function which accepts
N inputs then computes the result. Where N is the number of variables in
the function.
Taking this to the extreme(accepting both values and commands) would be
an interpreter( or script evaluator ).
This is partial evaluation at runtime.
Or you could run the compiler on the function each time a new value or
type is presented. This is compile time partial application and is the
one represented by D templates.
It reinforces my belief that data is the only piece of most programs
which will not change much. The inputs define the program. Looking over
some of the most reusable programs out there(compilers, web browsers,
spreadsheets) they are completely defined by their inputs.
-DavidM
PS. If I am understanding this incorrectly, please speak up and I will
eat my humble pie.
More information about the Digitalmars-d
mailing list