Is case var(var x, var y) a valid syntax ?
forax at univ-mlv.fr
forax at univ-mlv.fr
Mon Sep 7 21:56:05 UTC 2020
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "Guy Steele" <guy.steele at oracle.com>, "Alan Malloy" <amalloy at google.com>,
> "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Lundi 7 Septembre 2020 19:46:51
> Objet: Re: Is case var(var x, var y) a valid syntax ?
>> I disagree with that rational because a deconstructor is an instance method, so
>> you need to do an instanceof first,
>> said differently P(...) is a deconstruction pattern which is equivalent to
>> instanceof P p && var values = p.__name_of_the_deconstructor()
> At root, I think a lot of your frustration is that you are imagining a different
> model for what pattern matching means in the language. (I’m sure there are many
> different possible ways we could add pattern matching to Java.)
> In fact, I think you are not disagreeing with the rationale, you are disagreeing
> fundamentally with the model of how deconstruction patterns work in the current
> model. Deconstruction patterns are declared members, like constructors. The
> language arranges for them to be invoked as part of core linguistic operations
> (object instantiation for constructors, pattern matching for deconstructors.) I
> get that you have another model in mind, but if you want to convince people
> yours is better, you have to put the model on the table. Believe me, writing
> this up clearly, consistently, and completely is not a small task, but if you
> want to move the design, that’s the first step.
The deconstruction pattern is a special case of type pattern, both starts by doing a typecheck (an instanceof), what is different is how they bind variables after the typecheck.
So having the type inference on the type used by the typecheck working for the type pattern but not for the destruction pattern strike me as weird.
At the same time, i understand why people can find the syntax awkward. I just want to be sure that it's not awkward just because it's a new syntax.
By example, with this switch, that has two cases that are semantically identical
switch(point) {
case Point p where p.x() == 0 -> ...
case Point(var x, var _) where x == 0 -> ...
}
one may want to use inference
switch(point) {
case var p where p.x() == 0 -> ... // this one is Ok !
case var(var x, var _) where x == 0 -> ... // this one is Not ?
}
How the deconstructors are represented in the surface language, how they are called or how the data values flow to the bindings are another stories for another time.
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200907/74df7ffa/attachment.htm>
More information about the amber-spec-experts
mailing list