-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New Syntax for Capture Variables and Explicit Capture Polymorphism v3 #23063
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
base: main
Are you sure you want to change the base?
Conversation
9e1754b
to
ff07e02
Compare
@odersky making these behave analogously to higher-kinded type parameters makes me wonder if
|
If the lower bound of a capture variable is temprarily |
It's not impossible to add the lower bound (& upper bound) during parsing. But if the mental model is "this is another kind", then the proposed scheme will be irregular for someone who is familiar with the syntax- and subtyping-rules for higher-kinded types in Scala. |
I don't think we should make a capture variable a real "kind"... |
* Refrain from using a flag and in favor of an attachment. * Rule out context bounds entirely for capture vars.
@noti0na1 |
Closes #22490
Builds on #22725
Supersedes #22902
This syntax for capture variables and members caters to the view that "they are another kind", and most conventions we know from higher-kinded type parameters carry over.
A postfix
^
(analogous to[_]
) indicates that a type parameter/member ranges over capture setsThese variables can be bounded by capture-set literals:
Just as with higher-kinded type parameters, the kind is "contagious", and we can often avoid the hat if the bounds are concrete capture sets or other capture variables:
Capture variables will be erased if capture checking is turned off. In non-capture-checked code, they are essentially type variables within the interval
>: caps.CapSet <: caps.CapSet
. With capture checking turned on and without explicit bounds, the interval corresponds to>: caps.CapSet^{} <: caps.CapSet^{caps.cap}
.Tasks