New ask Hacker News story: Ask HN: Autocurrying Syntax Sugar?

Ask HN: Autocurrying Syntax Sugar?
2 by danhab99 | 0 comments on Hacker News.
Full disclosure: I'm not a computer scientist, I'm just a programmer who uses these tools. Also I mainly use javascript and go, I need to spread out more but these two tools fulfill 99% of all my needs. I had a 2am idea and when I looked it up I couldn't find any mention of someone else thinking of it. Here it is: Function currying is a method for saving arguments on the callstack so they don't have to be copied in memory between calls. Here's a javascript example of currying: ```js const add = (leftOp) => (rightOp) => leftOp + rightOp; const addThree = add(3); console.log(addThree(4)); // 7 console.log(addThree(-2)); // 1 ``` I think all PL that support the "putting-functions-in-variables" paradime can do this. BUT. If you try to call a normal function that requires all of its arguments up front without all the arguments it will throw an error. So what if it didn't? What if instead of throwing an error, the function call returns a curried function with the first arguments filled and the unfilled arguments left to be inputted. ```js // with autocurrying const add = (leftOp, rightOp) => leftOp + rightOp; const addFive = add(5); // addFive is defined like addFive = (rightOp) => 5 + rightOp console.log(addFive(3)); // 8 ``` This could work in Javascript(/Typescript), Python, Go and similar languages. By encouraging currying you could potentaily get memory saving, readibility, and performance. But I won't ever try to sell you a stack of pros without a foundation of cons: any syntax sugar has the potential to cause logic bugs, reference bugs, and missuse. What do you guys think?

Comments