<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>"Brian Goetz" <brian.goetz@oracle.com><br><b>To: </b>"Red IO" <redio.development@gmail.com>, "Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"Tesla Ice Zhang" <ice1000kotlin@foxmail.com>, "amber-dev" <amber-dev@openjdk.org><br><b>Sent: </b>Sunday, January 22, 2023 3:00:05 PM<br><b>Subject: </b>Re: About underscores in type arguments / partial type arguments<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;"><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" target="_blank">https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system</a>.)<br></font></font></blockquote><div><br></div><div>I don't know Rust well, i've just played with it but as i understand it does not use global inference but more a kind of delayed inference, there is a type (say Unknown) which say that there is no constraint and later when constraints are found, Unknown is replaced by type inferred. I've seen something similar in Haxe (which predates Rust).<br data-mce-bogus="1"></div><div>It works well in Rust because Rust uses a type flow algorithm where the type of a variable change depending on the control flow (like Kotlin or TypeScript).<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>regards,<br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></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 class="moz-cite-prefix">On 1/21/2023 5:40 AM, Red IO wrote:<br>
    </div>
    <blockquote 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" class="moz-txt-link-freetext" target="_blank">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" 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" 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" class="moz-txt-link-freetext">https://kotlinlang.org/docs/whatsnew17.html#underscore-operator-for-type-arguments</a><br data-mce-bogus="1"></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" 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><br></blockquote></div></div></body></html>