New pattern matching doc
Remi Forax
forax at univ-mlv.fr
Thu Jan 7 21:39:46 UTC 2021
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Mercredi 6 Janvier 2021 21:52:19
> Objet: New pattern matching doc
> I have pushed
> [
> https://github.com/openjdk/amber-docs/blob/master/site/design-notes/pattern-match-object-model.md
> |
> https://github.com/openjdk/amber-docs/blob/master/site/design-notes/pattern-match-object-model.md
> ]
> to the amber-docs repo, which outlines the direction for how patterns fit into
> the object model.
Hi Brian,
i'm glag that "deconstructor" can now be virtual.
Given that a "deconstructor" is now very like a method but with the caveat that you can not call them directly,
i think it's time to change the name from "deconstructor" to xxx method, let say "case method" (i'm sure there is a better name), because they are closer to real methods than initially anticipated.
Otherwise, "adhoc polymorphism" is a kind of overloaded ( :) ) term, it is used for overloading, and several other exotic kinds of polymorphism in the literature,
i think that pattern polymorphism or case polymorphism is a better term.
I think there is a missing discussion about what a case method can return, it can return something saying no match, it can return something saying there is a match and here are the values.
One question is how the values are associated to the bindings, in the pattern, you have a notion of order, i.e. Point(var x, var y), x is the first binding and y the second, but in your proposed syntax, there is no notion of order, you associate a name to a value.
If you remember, that's why i ask if when a pattern calls the case method, it's a call by name or a call by value.
Given that you want overloading, it has to be a call by value, but in that case, the proposed syntax looks very weird.
I would prefer a syntax that convey that the semantics is not a call by name
By example, something along that line
class Optional<T> {
T value;
case of() {
if (value == null) {
return no-match;
} else {
return match(value);
}
}
case empty() {
if (value == null) {
return match;
} else {
return no-match;
}
}
}
Here the "return" is redundant, but my point is not to discuss the syntax but the associated semantics, so the syntax is just here to illustrate the point.
regards,
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20210107/6e73004d/attachment.htm>
More information about the amber-spec-experts
mailing list