Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currying? #3

Closed
kevinSuttle opened this issue Jun 17, 2016 · 4 comments
Closed

Currying? #3

kevinSuttle opened this issue Jun 17, 2016 · 4 comments

Comments

@kevinSuttle
Copy link

Forgive my ignorance, but isn't "partial application" the same thing as "currying"? http://javascript.crockford.com/www_svendtofte_com/code/curried_javascript/

@stylemistake
Copy link

stylemistake commented Jun 17, 2016

I had the same question some days ago.

Technically it isn't currying, because currying is a creation of a function, where partial application outputs a function with remaining arguments, which can be called, and its output can be called, until all arguments are applied. In a good implementation, curried functions should also be uncurriable.

In javascript, it would look like this:

const fn = (a, b, c) => a + b + c;

const curried = fn.curry();
curried(1)(2)(3); // 6
curried(1, 2); // (c) => ...

const uncurried = curriedFn.uncurry();
uncurried(1, 2, 3); // 6
uncurried(1, 2); // NaN

And what author of this repository proposes, is the actual and explicit partial application, which isn't currying.

But I must admit - papp is a very bad name, and I see why we would want to call it curry instead.

P.S. Or even better, partialLeft and partialRight, as in Ramda and Lodash.

@gilbert
Copy link
Owner

gilbert commented Jun 17, 2016

@stylemistake is correct; currying is making a function only ever take one argument. You can write curried functions today quite easily in JS:

// currying!
var add = (x) => (y) => x + y

var result = add(10)(15)
result //=> 25

@stylemistake Be careful about how you express arguments. You say papp is a very bad name. If I were to counter by saying papp is a very good name, we have both effectively said nothing at all :)

I chose papp because 1. it's short for "partial application", and 2. it's short. You kind of lose the brevity benefits with a longer name such as partialLeft:

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

var addTen = add.partialLeft(10) // <-- long!
var addTen = add.bind(null, 10)
var addTen = (y) => add(10, y)
var addTen = add.papp(10)

Other languages such as Haskell and Elm don't have this problem because their functions are curried by default. But alas, we have JavaScript.

P.S. partialRight is related to #2

@Alexsey
Copy link

Alexsey commented Jun 17, 2016

I'm also sure that what ever name it would be it Must be short. Other way it's not better than rewriting with arrow function. Why Lodash and Ramda has such? Because those where taken before ES6 came out

Shortness is extremely important when you are inlining function inside another one like map, filter or similar

@kevinSuttle
Copy link
Author

Thanks for the thorough explanations!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants