3 ms·
Note that in Rust 2018, trait object syntax moves to using `dyn` (see https://rust-lang-nursery.github.io/edition-guide/2018/transitioning/traits/dyn-trait.html
by chrismorgan 8y ago
Note that in Rust 2018, trait object syntax moves to using `dyn` (see https://rust-lang-nursery.github.io/edition-guide/2018/transitioning/traits/dyn-trait.html https://rust-lang-nursery.github.io/edition-guide/2018/trans...), so that your second code block will actually be:
fn foo(t: &dyn SomeTrait)
&dyn SomeTrait and &impl SomeTrait are then more directly comparable. “&impl SomeTrait” should be read as “a reference to a type implementing SomeTrait”.
It’s different from the angle-bracketed generic syntax you may be used to, but I think it’s generally superior. I certainly find it much easier to write and read than the generic syntax or generic-syntax-with-where-clause versions. Well, I say generally superior—but its potential downfall is the turbofish issue, that impl in argument place is not just sugar for the generic syntax. And thus that for now impl in argument place is arguably unsuitable for library code and only suitable for application code. We’ll see how that pans out.
You mention higher-kinded types: there is actually a plan now for a feature equivalent to HKT, generic associated types (associated type constructors), https://github.com/rust-lang/rfcs/pull/1598 https://github.com/rust-lang/rfcs/pull/1598, and I’m glad; note when I say that that I was one of the few that campaigned before Rust 1.0 for explicitly not touching HKT for a few years purely for marketing reasons—they’re scary and will put people off Rust. But certainly I have encountered a couple of situations where generic associated types would substantially improve ergonomics in my HTTP and web work, and this is a proper Rust-flavoured take on the concepts behind HKT. I believe it will be good to have.
I am still a bit anxious about the volume of change happening, just as you, others, and graydon just now on the forum post.
- wuschel 8y agoQuick question: was there a time when Rust was closer to the syntax format of Haskell/Ocaml? e.g. Type declaration Function declaration
- chrismorgan 8y agoNo. Rust has always had C-family syntax. You can look at the first public commit with the code at https://github.com/rust-lang/rust/tree/d6b7c96c3eb29b9244ece0c046d3f372ff432d04 https://github.com/rust-lang/rust/tree/d6b7c96c3eb29b9244ece... ; src/test/run-pass shows lots of examples of the syntax.
- nixpulvis 8y agoI still haven't used it enough to have a real opinion, but I think `dyn` is the one thing in all this I feel is a bad change. Otherwise the module system is going to be much nicer, `impl Trait` has been a thing needed since day 1, and some new forms of elision are nice. I'll be curious to see if I like the `match` changes though.
- steveklabnik 8y agoIncidentally, the match changes work in stable today. The audience for the edition isn’t just those who follow Rust closely, but for those who don’t. And even for those who do, we want to take a look at some of the things that make writing Rust feel differently in the last few months. Turns out the match stuff was good enough to stabilize a bit earlier, even though it was designed with all of these other features.
- nixpulvis 8y agoYea fair point, just haven't been writing enough rust over the last few months :( There remains a small part of me that enjoyed the explicitness of fighting the compiler to understand what type I was actually dealing with (forced learning).
- steveklabnik 8y agoHave you read https://terrytao.wordpress.com/career-advice/theres-more-to-mathematics-than-rigour-and-proofs/ https://terrytao.wordpress.com/career-advice/theres-more-to-... before? I find it extremely interesting. Sounds like you may be on the "rigorous" stage. This kind of feature helps the pre and post stages, at the expense of that one.
- nixpulvis 8y agoI hadn't. It's a great peice though. The rust programmer who adds and removes `&` and `ref` blindly is in phase 1, the part I'm claiming to like is more or less phase 2, where some real thought goes into it, "here I have a &Option, so here it must be &Some(...)" and so on. Phase three is practical, much like how I might tell someone in casual conversation that something took orders of magnitude more time, without worrying too much about what magnitude I'm really talking about. This can give you the head space to tackle "real problems". As rust matures (and its users with it) I can understand the desire for these conveniences. I do feel the language loses some of its educational prowess. I'm always arguing in favor of more Racket like ideas, but the whole family of languages thing helps in this regard, but makes for quickly divergent communities. </ramble>