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 upOwned references to contents in an earlier stack frame (`&own`, `&move`, etc) #998
Comments
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Are there any unresolved questions? |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Jan 18, 2016
|
It sounds like a comonad actually, so state machines, etc. There is an RFC proposing I'd imagine this could be done by delegating several There isn't afaik any reason to touch the usual comonad definition here, but comonads do run close to object oriented programming http://www.haskellforall.com/2013/02/you-could-have-invented-comonads.html It's not too odd that an RFC for adding a form of inheritance would help add the most well understood application of comonads too. |
This comment has been minimized.
This comment has been minimized.
|
Alternatively, is there a clean way to make references more extensible in general? It seems to me that an alternative approach that allowed substitution of references for anything implementing Deref would be really useful. For example, in public library structs with internal references, it seems like references are too limiting: really, the user should be able to provide a reference, Rc, Arc, Box, or whatever they please. The obvious answer is to make every such struct generic on Deref, but that adds a lot of unnecessary boilerplate ( |
This comment has been minimized.
This comment has been minimized.
|
@cramertj I think what you are asking for are higher-kinded types (HKT)? so that one could have a library parameterized over a type constructor from type to type (and I guess also in this case the type resulting from the construction would be expected to implement Deref in an appropriate manner); then you would instantiate such a library with the desired reference type constructor: Rc, Arc, Cow, .,.. If that is indeed what you are describing, then yes, HKT is something the community has been discussing for a long while. (However, I believe it to be separate from the construct described on this ticket, at least in the sense that whether or not we add HKT is largely orthogonal to whether we add a |
This comment has been minimized.
This comment has been minimized.
|
Yes, I'm essentially proposing a specific use case of HKTs. I wasn't sure whether or not this RFC was designed with HKTs in mind-- perhaps I don't properly understand the concept of |
nikomatsakis commentedMar 21, 2015
•
edited
A common request is to have a way to pass a reference that actually owns its referent. The idea originated long ago in an attempt to find a suitable type for
Drop, but it's not a perfect fit there (you really want to not own the struct being dropped, just its fields). It has since resurfaced as a means to pass ownership of unsized types (but see #990 as well) and various other use cases.Postponed RFCs