<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<font size="4"><font face="monospace">The main choices you get in
selecting a type inference scheme are (a) where to gather
constraints and (b) when to solve them. Java chooses, sensible,
to do its solving at the level of a single statement or
expression, rather than the entire body of a method. While this
might seem like "throwing away useful information", it enables
more local reasoning; you don't have to worry about
implementation details hundreds of lines away affecting the
result of inference. I think its safe to say we made our choice
a long time ago and are still happy with it.<br>
<br>
(BTW, Rust didn't invent global type inference either; see
<a class="moz-txt-link-freetext" href="https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system">https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system</a>.)<br>
</font></font><br>
<div class="moz-cite-prefix">On 1/21/2023 5:40 AM, Red IO wrote:<br>
</div>
<blockquote type="cite" cite="mid:CABKyW1vOHznYs-YfrZnv9n1oir09oR3NZa=50SN_PXg9=KcFRA@mail.gmail.com">
<div dir="auto">I'm not sure how well this would fit in Java, but
rust has long reaching backwards inference. Example:
<div dir="auto">var hashmap = new Hashmap<>();</div>
<div dir="auto">hashmap.add(5, "Hello");</div>
<div dir="auto">Where the first use of a type variable here int,
String infers the type of the hashmap.</div>
<div dir="auto">This would allow patterns to avoid specifying
the type variables they want by inferring them by usage inside
the pattern.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Great regards </div>
<div dir="auto">RedIODev </div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Sat, Jan 21, 2023, 08:01
Remi Forax <<a href="mailto:forax@univ-mlv.fr" moz-do-not-send="true" class="moz-txt-link-freetext">forax@univ-mlv.fr</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:#000000">
<div><br>
</div>
<div><br>
</div>
<hr id="m_-6008077281224607691zwchr">
<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"><b>From:
</b>"Tesla Ice Zhang" <<a href="mailto:ice1000kotlin@foxmail.com" target="_blank" rel="noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">ice1000kotlin@foxmail.com</a>><br>
<b>To: </b>"amber-dev" <<a href="mailto:amber-dev@openjdk.org" target="_blank" rel="noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">amber-dev@openjdk.org</a>><br>
<b>Sent: </b>Saturday, January 21, 2023 3:23:39 AM<br>
<b>Subject: </b>About underscores in type arguments /
partial type arguments<br>
</blockquote>
</div>
<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">Hi
all,<br>
<div>Is there any discussion related to partially
specified type arguments (which are left for
inference)? I just saw that Kotlin 1.7 added support
for that. It would be nice if Java can have that
too: <a href="https://kotlinlang.org/docs/whatsnew17.html#underscore-operator-for-type-arguments" target="_blank" rel="noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">https://kotlinlang.org/docs/whatsnew17.html#underscore-operator-for-type-arguments</a></div>
<br>
<div>The demonstration of the feature in the above
document is also applicable to Java.</div>
</blockquote>
<div><br>
</div>
<div>Yes, this has been discussed several times not only
in the context of patterns but also in the context of
inference in general.<br>
</div>
<div><br>
</div>
<div>For patterns, currently you have to repeat all type
arguments<br>
</div>
<div><br>
</div>
<div> Map<String, Integer> map = ...<br>
</div>
<div> switch(map) {<br>
</div>
<div> case HashMap<String, Integer> m -> ...<br>
</div>
<div> ...<br>
</div>
<div><br>
</div>
<div>we talk about simplify it using<br>
</div>
<div> case HashMap<> m -> ...<br>
</div>
<div> <br>
</div>
<div>but this means also supporting</div>
<div> if (map instanceof HashMap<> m) { ...<br>
</div>
<div><br>
</div>
<div>and maybe also supporting<br>
</div>
<div> if (map instanceof HashMap) {<br>
</div>
<div> var m = (HashMap<>) map;<br>
</div>
<div> ...<br>
</div>
<div> }<br>
</div>
<div> <br>
</div>
<div>One issue is that the inference rules are not the
same as the usual inference rules, because you want to
be able to infer something like HashMap<?,?>
while you do not want to infer new
HashMap<?,?>() in the general context.</div>
<div><br>
</div>
<div>Currently, we are trying to see if we can avoid to
specify the angle brackets all together, so more "case
HashMap" than "case HashMap<>".<br>
</div>
<div>see <a href="https://cr.openjdk.java.net/~gbierman/jep432%2b433/jep432+433-20221115/specs/patterns-switch-record-patterns-jls.html#jls-18.5.5" target="_blank" rel="noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">https://cr.openjdk.java.net/~gbierman/jep432%2b433/jep432+433-20221115/specs/patterns-switch-record-patterns-jls.html#jls-18.5.5</a><br>
</div>
<div><br>
</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"><br>
<div>Best regards,</div>
<div>Tesla</div>
</blockquote>
<div><br>
</div>
<div>regards,<br>
</div>
<div>RĂ©mi<br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>