-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: trait-declared associated type synonyms #5033
Comments
I don't think it's altogether straightforward :) --- but I do think it's something we should try and do. I'd like to discuss this and related issues at the work week. |
External iterators in traits may tie in to this issue as well:
|
Related bug: #6894. Though the various proposals may represent some divergence at this point. |
Nominating for Backwards-Compatible. |
Did not mean to do that. Meant to remark on the similarity between this and ML signatures. |
accepted for backwards-compatible milestone |
(This carries backwards compatibility risk in terms of APIs changing; but we're not decided on whether to take it. it's something we need to discuss in full detail in a work-week or roadmap meeting.) |
Has this been discussed in one of the meetings yet? |
We discussed the general matter at our last retreat but I think the |
Nominating because I believe this is out of scope for 1.0. |
switching to P-high. |
This issue has been moved to the RFCs repo: rust-lang/rfcs#313 |
Split up `use_self` ui test Part of rust-lang#2038 changelog: none
Rust's type system reflects many advances in the state of the art.
However, there is one feature (offered by C++ and ML) that is not present in Rust: The ability to declare within a trait a named type (and then each impl item would be obligated to bind that name to an appropriate type for the implementation).
Related work: See Garcia et al. 2003, especially section 6.2, 10.2, and 10.3. Another useful reference is Chakravarty et al 2005
The Haskell community calls such a construct an "associated type synonym."
Here is an small example to illustrate the idea.
First, the easy part: how such a feature would look at the level of trait and impl items:
Ideally one would extract the type from a trait by using a path, using a type parameter as a path component. So for example:
Note: I am aware that one can express currently express type synonyms in much the same way that one does in Java (or C#, or Eiffel; see Garcia et al paper): by making them a type-parameter of the trait itself. Rust's type-inference system does make that workaround more palatable, but it seems natural to enable the developer to express what they mean more directly: These types are obligations of the implementation, much like the functions declared in the trait, and thus it makes sense to express them the same way.
There are various issues to consider: e.g.:
Despite the above issues, this seems like a relatively straightforward change to the language (especially since one can already encode the pattern, so adding it should not inject e..g any type soundness bugs, right?).
The text was updated successfully, but these errors were encountered: