Next up for patterns: type patterns in switch
forax at univ-mlv.fr
forax at univ-mlv.fr
Fri Aug 14 00:01:11 UTC 2020
> De: "Guy Steele" <guy.steele at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "Brian Goetz" <brian.goetz at oracle.com>, "John Rose"
> <john.r.rose at oracle.com>, "amber-spec-experts"
> <amber-spec-experts at openjdk.java.net>
> Envoyé: Jeudi 13 Août 2020 19:22:46
> Objet: Re: Next up for patterns: type patterns in switch
>> On Aug 13, 2020, at 8:19 AM, [ mailto:forax at univ-mlv.fr | forax at univ-mlv.fr ]
>> wrote:
>> . . .
>> I wonder if we find it natural only because we are used to use the keyword
>> "default" inside a switch, . . .
> I think that may be so; but given that it is so, I am happy to exploit that
> fact!
>> I think i prefer using "default" (or any other keyword) only where it makes
>> sense and doesn't allow "default" to be propagated.
>> so
>> default Pair p: ...
>> is ok but
>> default Pair(Box(Frog f), Bag(Object o)): …
>> should be written
>> case Pair(Box(Frog f), Bag(default Object o)): …
> I think you intended that last line to read
> case Pair(Box(default Frog f), Bag(default Object o)): …
yes, thank you
> and if so, I agree that this may be a better way to write it in the context I
> originally gave:
> switch (x) {
> case Pair(Box(Tadpole t), Bag(String s)): …
> case Pair(Box(Tadpole t), Bag(default Object o)): …
> case Pair(Box(default Frog f), Bag(String s)): …
> case Pair(Box(default Frog f), Bag(default Object o)): … // I originally had "
> default Pair(Box(Frog f), Bag(Object o)): …” here
> }
> But either way works, because of the subtle fact that if P: Pattern T, then Q is
> total over type T if and only if P(Q) is total over type P, so one can choose,
> on purely stylistic grounds, whether to use the “default” tag at the root of a
> pattern subtree that is total, or at all the relevant leaves, or for that
> matter at a relevant set of interior subtrees.
yes,
i'm advocating on putting it in the subtree because i find the resulting code more readable because you can see how the subtrees of each case are related to each other, the result seems "balanced" visually.
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200814/9dc490a9/attachment-0001.htm>
More information about the amber-spec-experts
mailing list