|
|
On 7/3/2011 14:16, Darren New wrote:
> of functions that only take one argument and only yield one result,
Oh, and the same mechanism lets you return multiple results.
f(x, y)[z] (in C syntax)
is really just f(x, y, z) in a functional language.
f(x, y) would, instead of an array or list, return a lambda that when you
pass it an integer argument it would return the appropriate element of the
result. So you could assign the result of f(x, y) to a variable and treat
it like an array, but in the math, it's just another function invocation.
And obviously f(x) is similarly a 2-dimensional array, where f(x)(y,z) is
accessing the 2D array at index y, z.
Basically, currying means that f(x,y,z) is identical to f(x)(y)(z). Sort of
like the way C unifies 2D arrays as a 1D array of 1D arrays. C only has to
state the rules of how a 1D array works, and then you can compose them up
into as many dimensions as you want. With currying, you only have to state
the rules for taking one argument and returning one result, and curry up as
many arguments and return results as you want.
--
Darren New, San Diego CA, USA (PST)
"Coding without comments is like
driving without turn signals."
Post a reply to this message
|
|