[EMAIL PROTECTED] wrote:
> 
> What does "curried" mean in the context used here?
> 

The term came from the name of Haskell B. Curry, who did significant
work in mathematical logic and formal systems.  Details vary with the
language (and with the explainer... ;-), but the basic idea can be
motivated from one simple question:  What if functions could never
have more than one argument?

This would force us to understand something like

    funct expr0 expr1

in a different way; instead of being a function of two arguments,
funct would be a function of ONE argument (expr0 above) whose value
is ANOTHER function of one argument, which would then be applied
to expr1, as if it had been mentally parsed as

    (funct expr0) expr1

A somewhat trivial example in REBOL is (cut-and-paste with slight
reformatting for readability):

    >> curried-sum: func [
           a [number!]
       ][
           func [
               b [number!]
           ][
               a + b
           ]
       ]

This defines a function which returns a function, as in:

    >> print mold curried-sum 3
    func [
        b [number!]
    ][
        a + b
    ]

However, applying that returned function gets to be a bit interesting:

    >> curried-sum 3 5
    == 5
    >> (curried-sum 3) 5
    == 5

The above both appear to REBOL as two expressions, with the value of
the second (the 5) returned as the net result.  One has to be a bit
more explicit, as in:

    >> do (curried-sum 3) 5
    == 8

Of course, we ARE getting a function back, as can be demonstrated by:

    >> plus3: curried-sum 3
    >> plus3 5
    == 8

A common use of currying (in languages that treat functions as true
first-class values) is to take a function of N arguments (N>1) and
construct a derived function of N-1 arguments by "fixing" one of the
arguments to the original function at a specified value.

-jn-

Reply via email to