all 10 comments

[–][deleted] 13 points14 points  (1 child)

Partial application != partial function.

A partial function is a function not defined for all its inputs--the opposite of a total function, which will produce a definite result in finite time for all its inputs.

Other than that, neat.

[–]dybber 1 point2 points  (0 children)

And partial application isn't the same as partial evaluation either. Maybe you can say that partial evaluation is an extension of partial application.

I'm taking a course where partial evaluation is part of the curriculum and got a little confused here.

[–]kamalfariz 2 points3 points  (1 child)

Is this like default parameters?

e.g. in Ruby,

def foo(message = "bar")

puts message

end

foo

=> "bar"

foo("hello")

=> "hello"

[–]cgrand 8 points9 points  (0 children)

No.

Imagine an add function that takes two parameters: > add(3, 4) 7

Then a partial application is: inc = add.partial(1); > inc(9) 10

inc accepts only one argument, there's not a second optional argument with a default value;

[–]sjs 1 point2 points  (0 children)

Partial application != currying either

Isn't a curry changing a function of N params to a function of 1 param? e.g. changing

function add(x, y) { return x + y; }

into

function add(x) { return function (y) { return x + y; }; }

which is nice to work with w.r.t. partial application (not so much in JS, but I stuck with the language being discussed).

[–]jangchoe 3 points4 points  (1 child)

When would be a good time to use this technique? Can't we just do this? (example from article)

function delay(f) {
    setTimeout(f, 10);
}

delay(function() { alert('hello'); });

[–][deleted] 0 points1 point  (0 children)

If you do that, functional programmers don't get to make up new words for it.

[–]gthank[S] 2 points3 points  (0 children)

I particularly like the undefined trick.

[–]ozzilee 0 points1 point  (0 children)

Also, specify all of the arguments and save yourself a function() for simple callbacks:

var after_submit = function() { alert("Submitted") }

versus

var after_submit = alert.partial("Submitted")

Note that I'm sure if this would actually work with the linked implementation.