<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Guy Steele" <guy.steele@oracle.com><br><b>To: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"Brian Goetz" <brian.goetz@oracle.com>, "amber-spec-experts" <amber-spec-experts@openjdk.java.net><br><b>Sent: </b>Thursday, April 4, 2024 5:04:30 PM<br><b>Subject: </b>Re: Member Patterns -- the bikeshed<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<br id="lineBreakAtBeginningOfMessage">
<div><br>
<blockquote>
<div>On Apr 4, 2024, at 9:30 AM, forax@univ-mlv.fr wrote:</div>
</blockquote>
<blockquote><br>
</blockquote>
<blockquote>
<div>
<div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;">
<div>
<div>Patterns are not dual of methods, pattern deconstructors are dual of methods, but this is a special case.<br>
</div>
<div><br>
</div>
<div>A pattern not only have a sequence of match results, it can have parameters too.<br>
</div>
<div>For example, I may want to introduce an instance pattern asInteger() in java.lang.String that works like Integer.parseInt() but not match instead of throwing an exception if the string does not represent an integer. I may also want that pattern to decode
 hexadecimal so like Integer.parsing(int radix), I want my pattern to also takes a radix as parameter. In that case, my pattern asInteger() has an int value as match result and has an int radix as parameter.</div>
<div><br>
</div>
<div>Using the carrier syntax, it's something like<br>
</div>
<div>  carrier(int value) asInteger(int radix) { ... }<br>
</div>
<div><br>
</div>
<div>or without the carrier syntax but with a keyword pattern, it's something like<br>
</div>
<div>  pattern (int value) asInteger(int radix) { … }</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</div>
<div>I think what is missing is a necessary shift in terminology under Brian’s new proposal: if parameters are needed for a pattern, then in effect you curry it. In this new model, `asInteger` is not a pattern; rather, it is a pattern factory—that is, a method
 that returns a pattern. This is possible because of the introduction of SAPs, so that a pattern can be expressed using lambda syntax.</div></blockquote><div><br></div><div>This is super confusing.<br data-mce-bogus="1"></div><div>For curryfication, you need at least one parameter, so the SAP needs have one parameter but at the same time a SAP abstracts a pattern and pattern can not have a parameter ?<br></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<div><br>
</div>
<div>So we should speak of method `asInteger` as a pattern factory, and `asInteger(16)` as a pattern.</div></blockquote><div><br></div><div>You mean, asInteger().apply(16) or SAP unlike SAM can to be called directly using parenthesis ?<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>You also</div><div>- loose the ability to have several overloads, asInteger() and asInteger(16) can not be both valid at the same time if you have currification (at least in Java).<br data-mce-bogus="1"></div><div>- you need a new way to distinguish between a pattern and a pattern factory, the former has bindings, the later return a SAP interface.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>So we have a small/medium feature "pattern method" but for some reasons I do not understand instead of being a special kind of method, it's an entirely new concept, pattern.<br data-mce-bogus="1"></div><div>The body of a pattern works like a body of a method but for some reasons i do not undesrtand for returning the binding values, you have to use the name of the pattern (apart if this is a single abstract pattern because in that can it's the interface) and for returning no match, this is implicit. Some existing languages work like that but not Java.<br data-mce-bogus="1"></div><div>The parameters of a pattern instead of being method parameters, for some reasons i do not understand uses curryfication. Some languages work like that but not Java.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>This is very confusing.<br data-mce-bogus="1"></div><div>Again, why a pattern is not a new kind of method with a binding list instead of a return type and in the body, one can return match(val1, val2, ...) or return nomatch ?</div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<div><br>
</div>
<div>—Guy</div>
<div><br>
</div></blockquote><div><br></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>