Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: trait-declared associated type synonyms #5033
Comments
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
External iterators in traits may tie in to this issue as well:
|
This comment has been minimized.
This comment has been minimized.
|
Related bug: #6894. Though the various proposals may represent some divergence at this point. |
This comment has been minimized.
This comment has been minimized.
|
Nominating for Backwards-Compatible. |
bblum
closed this
Jul 25, 2013
bblum
reopened this
Jul 25, 2013
This comment has been minimized.
This comment has been minimized.
|
Did not mean to do that. Meant to remark on the similarity between this and ML signatures. |
This comment has been minimized.
This comment has been minimized.
|
accepted for backwards-compatible milestone |
This comment has been minimized.
This comment has been minimized.
|
(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.) |
This comment has been minimized.
This comment has been minimized.
|
Has this been discussed in one of the meetings yet? |
This comment has been minimized.
This comment has been minimized.
|
We discussed the general matter at our last retreat but I think the |
This was referenced Sep 5, 2013
This comment has been minimized.
This comment has been minimized.
|
Nominating because I believe this is out of scope for 1.0. |
SimonSapin
referenced this issue
Dec 9, 2013
Closed
Get rid of the DOM/content tree traits in util::tree #1357
This comment has been minimized.
This comment has been minimized.
|
switching to P-high. |
erickt
referenced this issue
Mar 11, 2014
Closed
serialize::Decodable decode() should return a IoResult/DecodeResult? #12292
larsbergstrom
referenced this issue
Jul 24, 2014
Closed
Tracking issue for Rust feature requests #2854
brson
added
the
A-servo
label
Sep 16, 2014
rust-highfive
referenced this issue
Sep 24, 2014
Closed
RFC: trait-declared associated type synonyms #313
This comment has been minimized.
This comment has been minimized.
|
This issue has been moved to the RFCs repo: rust-lang/rfcs#313 |
pnkfelix commentedFeb 19, 2013
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?).