-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Generalize over mut and non-mut items #976
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
Conversation
For better readability and to retain more of the proper CamelCase and snake_case looks for traits, structs and functions, we could change them from being the prefix |
👍 Maybe not this syntax, but being generic over mutability is often useful. I believe that all |
@mahkoh I thought about putting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this syntax is ambiguous between self.opt
-
bar()
and self.opt-bar()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reem Who do you mean it's ambiguous to?
- The parser
- The compiler
- Programmer who is reading quickly and doesn't have syntax highlighting
It shouldn't be ambiguous to the first two, because the opt
keyword followed by one or more white space followed by -
would always be a compile-time error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the parser, but I guess it's not ambiguous if you ban the ambiguity ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the use of -
note: allowing -
in identifiers is one of the alternatives in #940 (though I can't say many people seem interested).
Being generic over mutability is definitely useful, but I think a lot of careful thought is necessary before we settle on any specific incarnation; there are both many conceptual consistency and practical issues that need to be considered. Unfortunately, I'm not convinced this proposal is up to dealing with the magnitude of this challenge. For instance, it doesn't cover abstracting over the "by-value" mode at all, meaning it can't be used to collapse the |
I agree with @reem in that it needs much more thought. Such extensions tend to have tricky edge cases which aren't apparent from a few simple examples. I also don't see a mention of HKT, which may solve the same problem in a more general way. |
Yeah what we want to do is parametrize the capabilities of pointer types. This proposal suffers from the similar expressiveness issues as |
Another source of inspiration might be this presentation and the many references mentioned in it. In particular I wonder if we couldn't think of our reference types as being a combination of a pointer plus the capability to access it, after a similar fashion as suggested therein:
...or something like that. I suspect this couldn't really work as-is, because our lifetimes aren't quite the same thing as their regions (I believe it's possible for two disjoint pieces of memory to have the same lifetime?), but perhaps the idea could still be useful somehow. (I'm an expert on neither.) (It gets harder if you also wish to consider |
@glaebhoerl cool slides! Also I'd guess that code that partially assigns + refines a pointer can be generic over various combinations of |
There's no question that there are many types that could usefully generalize over
this struct can be used with |
I'm also concerned about the unknowns here and think this duality is something we've lived with for a long time and can continue to do so. As @nikomatsakis there are potential other solutions. Let's not be hasty. Thanks for the thought-provoking RFC, but we're not going to pursue this avenue. |
Rendered