Nick Sabalausky wrote:

> "spir" <denis.s...@gmail.com> wrote in message
> news:mailman.3497.1302788057.4748.digitalmar...@puremagic.com...
>> On 04/13/2011 02:34 PM, bearophile wrote:
>>
>>>
>>> If a value of type T can be null, it must be declared as type
>>> Optional<T>, which may be abbreviated to T?
>>>
>>> String? name = process.args.first;
>>> if (exists name) {
>>>      writeLine("Hello " name "!");
>>> }
>>> else {
>>>      writeLine("Hello World!");
>>> }
>>>
>>> Use of an optional value must be guarded by the if (exists ... )
>>> construct. Therefore, NullPointerExceptions are impossible.
>>>
>>> This is exactly what I suggested for D in a enhancement request.
>>> It seems this kind of stuff is becoming a standard in new languages.
>>
>> +++
>>
>> But I guess optionality could, and should, extend to non-ref types; thus,
>> null is just a particular case of non-existence. And this would apply
>> especially on function parameters:
>>    void f (int i?) {...}
>>
> 
> Oh absolutely. Haxe has nullable-primatives which really comes in handly
> at times (it often prevents the need for a separate bool to keep track
> of). Only problem is that in Haxe, not only is nullable the default, but
> it doesn't even *have* any non-nullables at all, for any type.
> 
> 
>>
>> I don't get the diff between currying & partial app. And find this
>> feature much complication for close to uselessness.
>>
> 
> I'm not certain either, but I *think* partial application is just like
> currying except there's some sort of arbitrary limitaion on what
> combination(s) of paramaters you can choose to specify or not specify. And
> that limitation is based purely on what order the function defines its
> parameters. So basically, my understanding is that partial application is
> an arbitrarily-gimped currying.
> 

partial application is getting a new function out of an existing one where 
one of the arguments is fixed / bound. More or less what std.functional 
curry does, confusingly.

currying however doesn't involve specifying parameters at all, it means to 
get a function with one parameter out of a function with more than one 
parameter. This new function returns a function with one parameter, and so 
on and so forth until there is nothing left to curry. An example is clearer:

int foo(int a, int b, int c) {
    return a + b + c;
}

auto curriedFoo(int a) {
    return (int b) {
        return (int c) {
            return foo(a, b, c);
        };
    };
}

assert( curriedFoo(1)(2)(3) == 6 );


Whereas partial application could be something like:

auto partialApply(F)(int x, F fun) {
    return (ParameterTypeTuple!(F)[1..$] args) {
        return fun(x, args);
    };
}

assert( partialApply(1, &foo)(2,3) == 6);

Reply via email to