I think it would only be a problem if we want to use the same syntax for existentials and as short-hand for generics.
I am with @withoutboats in that reusing the same syntax would be controversial. I think impl Trait is actually very good, because it is in type position and means âhere is a single type that implement this Traitâ. In argument position, it would mean âgenericsâ with is more like âfor any combinations of types that implement these traitsâ. Using any sounds nice, using nothing would be better but we cannot do that. Anyhow, if we settle on that we want a different syntax for that no matter what, then impl Trait can proceed.
In particular, I remain to be convinced of the benefits of a short-hand syntax, since all the arguments Iâve heard are very weak.
C++ added a short-hand syntax recently (e,g, OutputIterator copy(InputIterator begin, InputIterator end, OutputIterator out);) and it pays of huge because:
- C++ generic syntax is very verbose, so there is a lot to win by using any shorter syntax
- They can introduce this syntax without adding keywords (for non-trait objects, for trait-objects they use
virtual Concept), so the syntax is really short.
- They can make the syntax always do the right thing because C++ âtype systemâ is simpler. They reuse it for generics in argument position, and for âloose existentialsâ in return type, variable type, and when passing a type to a generic, positions (
Concept bar(); std::vector<Concept> foo = { bar(); };).
In Rust, however, the generic syntax is already pretty short (considering all that it can do). Adding a shorter syntax for generics requires a contextual keywords, so it can never be as short as C++. Finally, the syntax cannot be made to always do the right thing, so the longer syntax will probably be need to be learned and known to disambiguate. That is, there is not so much to win, we cannot push it as far as C++, and beginners will probably need to learn both syntaxes anyways.
I think the teachability argument is also particularly weak. Those coming from languages with generics (like Java, C++, HaskellâŚ) wonât have many problems with the âlongâ syntax we currently have. Those coming from dynamic languages without generics donât even know what kind of problems generic do solve since they donât have them in their languages. This is hard on them no matter what we do, I worry about the shorthand syntax making this actually harder, since now you have to teach them two different syntaxes, and the situations in which they can use one and they must use the other, and they are going to ask why.
I would love a short-hand syntax that is really short and always does the right thing to exist in Rust. It just seems to me that finding that, if it exists, is going to take way more time than finishing all the other use cases of impl Trait, which are already complicated enough.
In particular, impl Trait allows doing things that cannot be currently done on Rust. The short-hand would just be sugar, it doesnât add anything new. Usability is very important, but I still have a hard time justifying lack of progress on impl Trait for a short-hand syntax that might not even exist.