Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up"Mutability polymorphism" #414
Comments
This comment has been minimized.
This comment has been minimized.
|
Yeah, this would be very useful I think. |
This comment has been minimized.
This comment has been minimized.
thehydroimpulse
commented
Oct 26, 2014
|
/cc me |
This comment has been minimized.
This comment has been minimized.
reem
commented
Oct 26, 2014
|
It would be even better if we could abstract over ownership status, i.e. we could collapse |
This comment has been minimized.
This comment has been minimized.
|
This would be great. Do you have any thoughts on how this could be added in a backwards compatible way in the future? |
This comment has been minimized.
This comment has been minimized.
reem
commented
Oct 26, 2014
|
Not really. I think this deserves consideration pre-1.0 because it would collapse and change traits which are lang items, such as the Deref, Fn and Index families. Code that implemented those traits would be broken. Parametrizing over mutability is much easier than parametrizing over ownership, since you can just say "if you have * note all syntax is super hypothetical |
This comment has been minimized.
This comment has been minimized.
|
Yeah, figuring out how to abstract over |
This comment has been minimized.
This comment has been minimized.
|
@reem I don't think it's as easy as that. &T is often less restrictive, in that much more general code structures are valid with & and than &mut. You can make multiple &'s, and &mut's often necessitate temporary wrangling to appease borrowck (although this may simply be a SESE artifact). You would have to assume that your ptrs are &mut's in some regards, and &'s in others. Of course, in a hypothetical polymorphic mutability world many of the restrictions that & provides would be swept away by virtue of presumably all getters being polymorphic and "just working". |
glaebhoerl commentedOct 25, 2014
It would be desirable to, at some point, grow the ability to abstract over the "mutability" of reference types. Currently, it is frequently the case that one must write separate "getter" methods for shared
&and unique&mutreferences, even though the bodies of these methods are exactly the same. This is especially bothersome when those method bodies are nontrivial.See an earlier discussion on reddit here.
Ideas for accomplishing this could potentially be borrowed from the research mentioned in this presentation, as well as from the Disciple language (a language with region types, effect types (e.g. mutation involving a region), and polymorphism over both).
This could also potentially allow the
Fn/FnMut/FnOnce,Deref/DerefMut,Index/IndexMut, and so forth hierarchies to be collapsed into single traits parameterized over capabilities / effects / constraints (whatever we choose to call them).