hemanth / functional-programming-jargon

Jargon from the functional programming world in simple terms!
http://git.io/fp-jargons
MIT License
18.6k stars 1.02k forks source link

Partial application as currying #124

Closed stereobooster closed 6 years ago

stereobooster commented 7 years ago

The simplest example for currying:

(A,B) -> C convert to (A) -> (B -> C)

So partial application is application to curried function

((A,B) -> C)(A)  convert to ((A) -> (B -> C))(A)

From this definition I can not see difference between Auto-currying and partial application. Am I wrong?

jethrolarson commented 7 years ago

You're not wrong, auto-currying is essentially dynamic partial application. The only reason to describe it as "curry" is due to libraries like Ramda and Lodash using it for the practice

On Tue, Nov 22, 2016, 7:24 AM stereobooster notifications@github.com wrote:

The simplest example for currying:

(A,B) -> C convert to (A) -> (B -> C)

So partial application is application to curried function

((A,B) -> C)(A) convert to ((A) -> (B -> C))(A)

From this definition I can not see difference between Auto-currying and partial application. Am I wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hemanth/functional-programming-jargon/issues/124, or mute the thread https://github.com/notifications/unsubscribe-auth/AAB-4KIdu8pHnSAOcqNWITSnEPiz-D7Oks5rAwkRgaJpZM4K5kE8 .

CrossEye commented 7 years ago

I think there is a difference.

When you partially apply k arguments to a function with n formal parameters, you get back a new function that still needs n - k arguments. (Assuming k < n, of course.)

When you auto-curry a function, you get a function that has useful behavior when supplied 1, 2, ..., or n arguments. If you supply k arguments, you get back an already auto-curried function with n - k formal parameters.

const f = (a, b, c, d, e) => a + b + c + d + e;

partial(f, 1, 2)  ≍  (c, d, e) => 1 + 2 + c + 2 + e;

// But if

const g = autocurry(f)(1, 2);

// then

g ≍ (c, d, e) => 1 + 2 + c + d + e
g ≍  c => (d, e) =>  1 + 2 + c + d + e
g ≍  (c, d) => e =>  1 + 2 + c + d + e
g ≍  c => d => e =>  1 + 2 + c + d + e

So you can call this "dynamic partial application", but it's not partial application as it's usually used.

stereobooster commented 7 years ago

Maybe add a bit of history nerdiness?

This replacement mechanism simplifies work in both combinatory logic and lambda calculus and would later be called currying, after Haskell Curry. While Curry attributed the concept to Schönfinkel, it had already been used by Frege.

jethrolarson commented 6 years ago

I think this is addressed in the current definitions. Reopen if you disagree.