4 ms·
I don't think currying is that big a deal, it's just syntactic sugar that might or might not make things easier to read, unlike ADTs or closures which are impor
by andrepd 1y ago
I don't think currying is that big a deal, it's just syntactic sugar that might or might not make things easier to read, unlike ADTs or closures which are important core concepts.
I'd love to have a syntax like
{ foo(%1, bar) }
standing for
|x| { foo(x, bar) }
though. I'm not aware of any language that has this!
- Munksgaard 1y agoElixir has this, which is close: &foo(&1, bar)
- tcfhgj 1y agoPowershell has this, why do you like this?
- masijo 1y agoClojure has this user=> (#(println %1 %2) "Hello " "Clojure") Hello Clojure
- tormeh 1y agoI'd argue that currying is actively harmful (I suspect you agree). I've seen functions take one argument in one source file, and the next argument in another source file. In JavaScript no less. Horrendous stuff. One of my most hated anti-features, along with Scala's implicits. These kinds of features are mostly misused rather than used.
- bunderbunder 1y agoFrom what I've seen, partial application tends to be used for utmost good in dialects of ML, and utmost evil most everywhere else. Chaotic neutral in R/tidyverse.
- tmoertel 1y agoMathematica has this: In[1]: Map((1 + #1)&, {a, b, c}) Out[1]: {a + 1, b + 1, c + 1} See https://reference.wolfram.com/language/ref/Function.html.en https://reference.wolfram.com/language/ref/Function.html.en for the full story.
- zelphirkalt 1y agoWhat is that & doing there? I thought it looks neat, but then that & ...
- tmoertel 1y agoThe & is a postfix operator that converts an expression into an anonymous function. See “Pure Functions”: https://reference.wolfram.com/language/tutorial/FunctionalOperations.html#17469 https://reference.wolfram.com/language/tutorial/FunctionalOp...
- GrantMoyer 1y agoC++ has this[1], kind of, but please don't actually use it. > for_each(a.begin(), a.end(), std::cout << _1 << ' '); Also, Scala has something similar as a first class feature[2]. [1]: https://www.boost.org/doc/libs/1_88_0/doc/html/lambda.html https://www.boost.org/doc/libs/1_88_0/doc/html/lambda.html [2]: https://scala-lang.org/files/archive/spec/3.4/06-expressions.html#placeholder-syntax-for-anonymous-functions https://scala-lang.org/files/archive/spec/3.4/06-expressions...
- icen 1y agoIn K the arguments are named x y z by default, so you just write: { foo[x, bar] }
- cobbal 1y agoswift has this as well { foo($0, bar) }
- int_19h 1y agoAs noted in other comments, a bunch of languages has it, but the problem with this syntax is that it doesn't generalize well. For example, let's say we have: foo(%1, bar(%1, 42)) does this desugar to: |x| foo(x, |y| bar(y, 42)) or to: |x| foo(x, bar(x, 42)) and do you trust the person reading this code later to remember which one it is?
- _flux 1y agoI think currying is an important concept and not sugar at all, as it means each function takes exactly one parameter, i.e. in OCaml foo bar baz is equal to (foo bar) baz. Of course, some other languages can try to emulate the use of currying and the original original idea no longer exists there. I'm relatively sure there exists such a language you are looking for, but I've forgotten its name :(. There was a syntax extension pa_holes for OCaml (which you perhaps know, as it is natively currying) that worked like (\ foo \1 bar) and it would become fun x -> foo x bar I'm sure the extension was inspired by some other language.. And the pa syntax extension extension mechanism for OCaml has been replaced by ppx a long time ago already; maybe the new system doesn't enable such succinct extensions.