[patterns] Nullability in patterns, and pattern-aware constructs (again)
John Rose
john.r.rose at oracle.com
Wed Jan 8 23:13:05 UTC 2020
On Jan 8, 2020, at 12:27 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>
> So, summary:
> - the null constant pattern matches null;
> - "any" patterns match null;
> - A total type pattern is an "any" pattern;
> - var is just type inference;
> - no other patterns match null;
> - existing constructs retain their existing null behaviors.
FWIW, I love this, because (a) it gives null a little niche
at the top (case “any") and bottom (case null) of the lattice
of patterns, and (b) it collapses two useful surface forms
of patterns into one essential kind (“any”).
I think, and have argued elsewhere, that although type
inference in general risks being a confusing “action at a
distance” phenomenon, this use of total type patterns
is constrained enough to be easily readable in normal
usage. (Hint: The total type pattern is constrained to
be the last one. So the type, if not “var”, is really just
a way of documenting the switch type.)
— John
More information about the amber-spec-experts
mailing list