News for hackers. Stuff that matters.
Re:Matt Godbolt sold me on Rust by showing me C++ by andrepd on Wednesday May 07, 2025 @06:02AM (#43913876)
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!
Re:Matt Godbolt sold me on Rust by showing me C++ by masijo on Wednesday May 07, 2025 @08:10AM (#43914655)
Clojure has this

    user=> (#(println %1 %2) "Hello " "Clojure")
    Hello Clojure
Re:Matt Godbolt sold me on Rust by showing me C++ by Munksgaard on Wednesday May 07, 2025 @06:34AM (#43914073)
Elixir has this, which is close:

    &foo(&1, bar)
Re:Matt Godbolt sold me on Rust by showing me C++ by tcfhgj on Wednesday May 07, 2025 @07:17AM (#43914288)
Powershell has this, why do you like this?
Re:Matt Godbolt sold me on Rust by showing me C++ by tormeh on Wednesday May 07, 2025 @08:24AM (#43914762)
I'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.
Re:Matt Godbolt sold me on Rust by showing me C++ by bunderbunder on Wednesday May 07, 2025 @11:39AM (#43917127)
From 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.
Re:Matt Godbolt sold me on Rust by showing me C++ by tmoertel on Wednesday May 07, 2025 @08:30AM (#43914803)
Mathematica 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 for the full story.
Re:Matt Godbolt sold me on Rust by showing me C++ by zelphirkalt on Wednesday May 07, 2025 @09:29PM (#43922222)
What is that & doing there? I thought it looks neat, but then that & ...
Re:Matt Godbolt sold me on Rust by showing me C++ by tmoertel on Friday May 09, 2025 @07:00PM (#43941722)
The & is a postfix operator that converts an expression into an anonymous function. See “Pure Functions”:

https://reference.wolfram.com/language/tutorial/FunctionalOp...

Re:Matt Godbolt sold me on Rust by showing me C++ by GrantMoyer on Wednesday May 07, 2025 @09:43AM (#43915598)
C++ 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

[2]: https://scala-lang.org/files/archive/spec/3.4/06-expressions...

Re:Matt Godbolt sold me on Rust by showing me C++ by icen on Wednesday May 07, 2025 @10:26AM (#43916123)
In K the arguments are named x y z by default, so you just write:

    { foo[x, bar] }
Re:Matt Godbolt sold me on Rust by showing me C++ by cobbal on Wednesday May 07, 2025 @04:27PM (#43920249)
swift has this as well

    { foo($0, bar) }
Re:Matt Godbolt sold me on Rust by showing me C++ by int_19h on Wednesday May 07, 2025 @10:10PM (#43922459)
As 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?
Re:Matt Godbolt sold me on Rust by showing me C++ by _flux on Thursday May 08, 2025 @08:44AM (#43925563)
I 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.