(no title)
glittershark | 5 years ago
struct Person<F> {
pub name: F<String>,
pub age: F<u32>,
}
where you can then have `Person<Option>` be a person that may or may not have all fields filled, and `Person<Box>` be a person with all fields definitely filled. This is something I find myself reaching for surprisingly frequently when writing rust, and I feel like it's a missed benefit of implementing higher-kinded types.[0]: https://reasonablypolymorphic.com/blog/higher-kinded-data/
All that said, I'm really excited to have const generics land! Props to all the amazing work by withoutboats and the entire rust team.
meetups323|5 years ago
glittershark|5 years ago
kazoomonger|5 years ago
a1369209993|5 years ago
Edit, for that matter, how do you deal with a `Person f` that includes a `f (Maybe Something)` without confusing "the user didn't specify a `Maybe Something`" with "the user specified a `Maybe Something` with value `Nothing`" (or vice versa)?
steveklabnik|5 years ago
adamch|5 years ago
twic|5 years ago
https://github.com/tim-group/higher-kinded-lifecycle/blob/ma...
(in this code, "idea" is a domain concept from the firm i worked for at the time - basically a recommendation to buy a stock, which is 'opened' on a certain date, and 'closed' when it no longer seems like a good recommendation)
My collegues didn't like it, and stuck to using separate types for objects in different stages of the lifecycle!
IggleSniggle|5 years ago
glittershark|5 years ago
michael_j_ward|5 years ago
https://rustyyato.github.io/type/system,type/families/2021/0...
viraptor|5 years ago
What's a practical use case for it? It's cool in theory, but I struggle to come up with something that doesn't use at most 2 implementations (just copy the struct then), or some API where the types don't mix and can be generated via a macro instead.