haasn / -g-pl

/g/ programming language
13 stars 2 forks source link

Partial application #17

Open haasn opened 12 years ago

haasn commented 12 years ago

Thinking about adding this. Example:

>implying addfive isn't >add 5;

Basically, what would happen when you call a function with less parameters than it requires is that it returns a new function, which takes whichever arguments are left. Basically, it would sort of be like writing:

>implying addfive isn't >function(y) >add 5 y;

The only difference is that with partial application, the already known parameters would be determined immediately. So it would be more like:

>implying addfive
{
    >implying x isn't 5
    >implying addfive wasn't >function(y) >add x y
}

But either way, the only downside this would have is it makes some errors harder to catch (eg. you forget a parameter, and get a ton of subsequent errors because you'd be passing around uncomplete functions instead of values)

It still has a few merits though, mostly for the sake of brevity.

Do you think it's worth it?

graydude commented 12 years ago

I agree that it would be nice to have this, but maybe we should add a special function that returns a reference to the function given as its argument, so we can avoid the extra errors.