4 ms·
I keep thinking Rust should allow you to skip the < > if there's only one generic argument. Like just say io::Result Vec u8. Much more lightweight and not ambig
by ben0x539 4y ago
I keep thinking Rust should allow you to skip the < > if there's only one generic argument. Like just say io::Result Vec u8. Much more lightweight and not ambiguous (but breaks macros people write). You can keep the angle brackets for multiple arguments like idk Vec HashMap<Option String, Result<i32, ()>>.
- zozbot234 4y agoThis would involve using whitespace as an operator. If you're going to do that (I'm not sure that it stays readable once you go beyond trivially small code snippets) I'd argue that the generic type should be postfix, as it is in the CrabML syntax. And yes, these proposed syntaxes for Rust are not practical because Rust's support for macro definitions relies on the existing syntax. But if you're willing to reimplement any macros, it becomes viable.
- ben0x539 4y agoThat's wild actually, I've been aware that ML languages exist and had a rough idea what they look like but I never realized they do postfix generics. I'm going to have to let that bake in my brain.
- lmm 4y agoThe postfix notation isn't particularly essential. Haskell has usual left-to-right application but the types are still written without extra syntactic clutter, e.g. "Vector Int".
- zozbot234 4y agoYes, left to right is more intuitive/ergonomic if multi-argument generics are common, as in both Haskell and Rust.
- WalterBright 4y agoD allows the () to be skipped for one template argument: X!(T) X!T are the same. This was Andrei's idea, and it worked out nicely.
- ben0x539 4y agoYeah, I think that's very cool and reads nicely in a lot of cases. D is definitely always a language that comes to mind thinking about "has lots of important features" + "doesn't look crufty".
- WalterBright 4y agoThe way the code looks was always a high priority for D. I suppose that dates back to my aviation experience, where if an airplane is beautiful it very likely flies well, too.
- ssokolow 4y agoThat was proposed and rejected for Rust recently: https://github.com/rust-lang/rfcs/pull/3267 https://github.com/rust-lang/rfcs/pull/3267 I was against because I felt that there should always be parens/brackets/braces (macros can use any of them) for better scannability when you're invoking an unclear amount of extra stuff behind the scenes. (An appeal to the "make costs explicit" side of Rust's philosophy that also requires explicit .clone() rather than copy constructors.) Here's the summary of why the consensus was "no": https://github.com/rust-lang/rfcs/pull/3267#issuecomment-1282943902 https://github.com/rust-lang/rfcs/pull/3267#issuecomment-128...