5 ms·
Sure, but it is pragmatic in other ways as well :) It takes ADT, but not function currying, and so on.
by Ygg2 1y ago
Sure, but it is pragmatic in other ways as well :)
It takes ADT, but not function currying, and so on.
- jeffparsons 1y agoI've occasionally wondered about the lack of currying in Rust; it feels like something that can be done mechanically at compile time, so why not support it? Perhaps to do it cleanly (without more magical privileged functions in core) would require variadic generics?
- bunderbunder 1y agoYou can absolutely curry functions in Rust. You just have to do it manually because there's no syntactic sugar for it. I think that's a good thing. A curried function is a function that takes one argument, and returns a closure that captures the argument. That closure might itself take another argument, and return a new closure that captures both the original argument and the second one. And so on ad infinitum. How ownership and borrowing works across that chain of closures could easily become a touchy issue, so you probably want to be making it as explicit as possible. Or perhaps better yet, find an easier way to accomplish the same task. Maybe use a struct to explicitly carry the arguments along until you're ready to call the function.
- skybrian 1y agoThis isn’t Rust-specific, but one reason a language designer might deliberately not implement currying is that it makes function call sites a bit harder to read. You need to already know how many arguments a function takes to make sense of the call’s return type.
- int_19h 1y agoCurrying is just syntactic sugar for a lambda that binds the first argument and passes the rest unchanged, and you can achieve the same level of conciseness in other ways - e.g. "pipeline" operators - but with a syntax that is more readable and more extensible. E.g. https://docs.rs/piping/latest/piping/ https://docs.rs/piping/latest/piping/
- andrepd 1y agoI 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.