[Omake] Semantics for curried functions, partial applications and keyword argument.

Aleksey Nogin anogin at hrl.com
Wed Aug 8 14:19:07 PDT 2007


On 08.08.2007 13:08, Jason Hickey wrote:

> This sounds good to me.  How about:
> 
>    - Functions that allow too many arguments should be annotated--I now 
> think the word "curry" is better:
> 
>         curry.f(A=1, x) = ...
>         f(B=3, 1, 2)
> 
>    - The "apply" and "applya" functions would be extended allow for 
> partial applications.
> 
>         add1 = $(apply $(add), 1)
>         f' = $(apply $f, A=3)

Yes, that's good.

>>> * If there are enough/too many arguments, the application happens, 
>>> and keywords are selected aggressively.  Order does not matter.
>>
>> "Order does not matter" would only hold if no keyword is defined more 
>> than once? Or do we remove each keyword from the allowable set after 
>> it's used?
> 
> No, I think it is no problem to allow duplicates.  I'm a little 
> hesitant, since duplicate keyword arguments are almost always an error 
> and it is nice to detect them statically.  But with currying it might be 
> better to allow duplicates.

Even with currying I think it's probably better to try to prohibit 
duplicates. However, we might want to consider application of a 0-arity 
curry function to a "unknown" keyword argument as forcing the 
evaluation, not as an error.

curry.f() =
   curry.g() =
     curry.h(key=1) =
        println($(private.key))

f(key=2) #prints 2

>>>   partial.f(A=2, B=3, x, y) =
>>>      add($A, $B, $x, $y)
>>>   g1 = $(f 0, A=4)   # g1's remaining parameters are (B=4, y)
>>>   g2 = $(f C=5)      # legal, but it may raise an error later
>>
>> Actually I would disagree here - do not we immediately fold the 
>> partial arguments into the closure? If so, then we'd know the keyword 
>> "C" is not allowed.
> 
> For normal functions yes, but not for curried ones.  g2 just has the 
> closure for $f--it doesn't know that f doesn't return a function that 
> takes a keyword argument C.

Well, I do not necessarily agree with the "g2 just has the closure for 
$f" approach. I think there is some value in making the partial 
applications slightly more eager - not create an extra layer of 
closures, but instead act as a functional update to the original 
closure. Partial application to a keyword argument will extend the 
environment and reduce the set of allowed keywords. Partial application 
to a normal argument will extend the environment and shorten the 
parameter list.

Aleksey
-- 
Aleksey Nogin, Research Scientist
Advanced Technologies Department, Information & System Sciences Lab
HRL Laboratories, LLC, Malibu, CA


More information about the OMake-Devel mailing list