Hello all,

We've redone the presentation to try to make the motivation & connections more 
clear. The main points are the following: we lift restrictions around primitive 
type patterns in nested positions, in top-level positions, around constant case 
labels and instanceof. The semantics for instanceof​ are naturally derived from 
pattern matching. Now instanceof​ can safeguard all permitted casts according 
to Chapter 5.

https://openjdk.org/jeps/8288476

Let us know of your thoughts.
Angelos
________________________________
From: Brian Goetz <[email protected]>
Sent: 26 January 2023 17:04
To: Guy Steele <[email protected]>
Cc: [email protected] <[email protected]>; Angelos Bimpoudis 
<[email protected]>; amber-spec-experts 
<[email protected]>
Subject: Re: Draft JEP on Primitive types in patterns, instanceof, and switch

Yes, pardon my quick typing.

More specifically, a case constant is not a _constant pattern_ (at least, not 
yet), it is just a constant case label.  Constants are typed, and they carray 
both a type match and a value match.  When you say

    case 0

this is a constant for an int, and doesn't match a floating point zero (if the 
match target is `float`, it won't even compile.)  Similarly, `case 0.0` is a 
constant for a float, and is not applicable to a match target of int.  (We do 
have the usual tolerance for matching int constants to shorter int types, as 
before.)

We may generalize these to constant patterns in the future, but right now, 
these are constant case labels and their semantics are derived from that of 
existing case labels.

On 1/26/2023 10:25 AM, Guy Steele wrote:


On Jan 26, 2023, at 9:36 AM, Brian Goetz 
<[email protected]<mailto:[email protected]>> wrote:

...

For comparing a variable to a constant, representational equality is the 
obvious interpretation; `case nnn` means "is it the number nnn".  This allows 
you to say `case NaN` and `case -0` and get the right answer (all of these 
relations agree on what to do about 1.0).

Careful: I think you had better say “case -0.0”; otherwise the constant 
expression “-0” will be reduced to “0” and only then converted to 
floating-point representation, producing +0.0.

Yes, floating-point is VERY fiddly.

—Guy


Reply via email to