<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hey Maurizio,</div><div dir="ltr"><br></div><div>If we are in agreement that using wildcards is not an important case, I'm not sure I understand why this does not slot well into the existing type system. Potentially I'm missing something.</div><div>On the other hand, something like: <span style="background-color:rgb(238,238,238)">method(@CodeReflection Function<T, R> f)</span> is another option that won't suffer from compiler issues, but per Paul might not be clear/secure enough.</div><div><br></div><div>I just want to say that Quotable is also far from being a perfect solution (personally, I think it is worse than the 2 above). Seems that it was chosen due to similarity to Serializable case and because it already exists. But "Serializable" is an old solution, that was introduced before annotations, not sure the same design would be done today.</div><div><br></div><div>P.S. I'm raising the above as my personal thoughts. I'm not part of the Babylon team and will totally understand if the above will be completely ignored.</div><div><br></div><div>Thanks,</div><div>Kosta</div><div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 9, 2024 at 2:46 AM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">maurizio.cimadamore@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>
<p><br>
</p>
<div>On 08/05/2024 22:56, Konstantin Triger
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Hi Maurizio,
<div><br>
</div>
<div>Looking on this, I'm wondering how important is this
case: <span style="color:rgb(51,51,51);font-family:Consolas,Inconsolata,Courier,monospace;font-size:11.05px;background-color:rgb(248,248,248)">Quoted<Function<?,
?>> f = (Integer i) -> </span><span style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:11.05px;color:rgb(221,17,68)">""</span><span style="color:rgb(51,51,51);font-family:Consolas,Inconsolata,Courier,monospace;font-size:11.05px;background-color:rgb(248,248,248)">;</span></div>
<div>The "practical" case is something like: <T, R>
RETURN_TYPE method(Quoted<Function<T, R>>
f).</div>
<div>Which should compile well because of inference.</div>
<div>And if someone insists on working with wildcards, so
he has an option.</div>
</div>
</div>
</div>
</div>
</blockquote>
<p>The specific case per se is not important. But if Babylon needs
more help from the language, I think whatever feature we add needs
to slot it correctly into the existing type system/inference
machinery. The Quoted<T> idea at the moment seems more a
case of a square peg in a round hole - but that's not to say that,
maybe, we'll come up with some clever idea to rescue that
approach.</p>
<p>Maurizio<br>
</p>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div><br>
</div>
<div>Kosta</div>
</div>
</div>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, May 8, 2024 at 3:19 PM
Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" target="_blank">maurizio.cimadamore@oracle.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div>
<p style="margin:0px 0px 1.2em">On 06/05/2024 18:50, Paul
Sandoz wrote:</p>
<div>
<blockquote type="cite">
<pre><blockquote type="cite" style="color:rgb(140,140,140)"><pre>Just wanted to mention that there might be alternative implementations addressing this requirement.
1. Structural quoting (a la C#) - derives from the variable type, e.g. Quoted<T>. So, the user understands that the lambda body will be accessible.
</pre></blockquote><pre>There are some challenges with Java’s type system, which is why we embedded up where we are with the current approaches. Maurizio is better able than I to describe these challenges.</pre></pre>
</blockquote>
</div>
<p style="margin:0px 0px 1.2em">Hi,<br>
we have explored approaches such as <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Quoted<T></code>
(where <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">T</code>
is a functional interface) early on. And found them a
bad fit for Java. The main issue we faced is that being
a functional interface, as per today’s JLS, is a
predicate on class declarations not types (there was
some intense discussion on this point during Java 8).
But here we have something that can be treated as a
functional interface or not, precisely depending on its
type (e.g. the type parameter). E.g. a <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Quotable<T></code>
is a functional interface or not depending on <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">T</code>.
This is a pretty deep big departure from how the spec
currently deal with functional interfaces.</p>
<p style="margin:0px 0px 1.2em">One possibility would be
for the compiler/spec to ignore the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Quoted<T></code>,
and just focus on the inner <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">T</code>,
and then add the quoting back, after type-checking. But
doing so leads to (bad) edge cases. For instance, Java 8
supports a form of inference of the target type from the
explicit lambda parameter types, in this case:</p>
<pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248);display:block">Function<?, ?> f = (Integer i) -> <span style="color:rgb(221,17,68)">""</span>;
</code></pre>
<p style="margin:0px 0px 1.2em">In this case, the type of
the lambda expression is not just <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Function<?, ?></code>
(the target type), but <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Function<Integer,Object></code>.
That is, the compiler tries to get rid of the wildcards
before attempting to type-check the lambda expression
(this step is performed to avoid wildcards popping up
when checking the lambda body). But with quoting, this
won’t compose well - e.g.:</p>
<pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248);display:block">Quoted<Function<?, ?>> f = (Integer i) -> <span style="color:rgb(221,17,68)">""</span>;
</code></pre>
<p style="margin:0px 0px 1.2em">Will give an error:</p>
<pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;background-color:rgb(248,248,248);white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block">error: incompatible types: Quoted<Function<Integer, Object>> cannot be converted to Quoted<Function<?, ?>>
Quoted<Function<?, ?>> f = (Integer i) -> “”;
^
</code></pre>
<p style="margin:0px 0px 1.2em">That is, the functional
interface type inferred by the compiler (by dropping
wildcards) is now incompatible with the target type
(because of the way in which generics type-argument
containment rules work). To make things work, the client
would need at least to do this:</p>
<pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;background-color:rgb(248,248,248);white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block">Quoted<? extends Function<?, ?>> f = (Integer i) -> “”;
</code></pre>
<p style="margin:0px 0px 1.2em">Overall it felt like we
were pushing against the physics of the language here.
Serializable lambdas (with all their limitations) were a
strong precedent to build on top of, which didn’t suffer
from any of the limitations described above.</p>
<p style="margin:0px 0px 1.2em">Maurizio</p>
<div title="MDH:PGRpdiBjbGFzcz0ibWFya2Rvd24taGVyZS13cmFwcGVyIiBkYXRhLW1kLXVybD0iIiBzdHlsZT0i
IiBtYXJrZG93bi1oZXJlLXdyYXBwZXItY29udGVudC1tb2RpZmllZD0idHJ1ZSI+PHAgc3R5bGU9
Im1hcmdpbjogMHB4IDBweCAxLjJlbSAhaW1wb3J0YW50OyI+T24gMDYvMDUvMjAyNCAxODo1MCwg
UGF1bCBTYW5kb3ogd3JvdGU6PC9wPgo8cCBzdHlsZT0ibWFyZ2luOiAwcHggMHB4IDEuMmVtICFp
bXBvcnRhbnQ7Ij48L3A+PGRpdiBjbGFzcz0ibWFya2Rvd24taGVyZS1leGNsdWRlIj48cD48L3A+
PGJsb2NrcXVvdGUgdHlwZT0iY2l0ZSIgY2l0ZT0ibWlkOkU0QjVDRDJGLTNBM0UtNDhGQS05NkY2
LTBGNzREMURGMjMyMkBvcmFjbGUuY29tIj48cHJlPjxibG9ja3F1b3RlIHR5cGU9ImNpdGUiIHN0
eWxlPSJjb2xvcjogIzhjOGM4YzsiPjxwcmUgY2xhc3M9Im1vei1xdW90ZS1wcmUiIHdyYXA9IiI+
SnVzdCB3YW50ZWQgdG8gbWVudGlvbiB0aGF0IHRoZXJlIG1pZ2h0IGJlIGFsdGVybmF0aXZlIGlt
cGxlbWVudGF0aW9ucyBhZGRyZXNzaW5nIHRoaXMgcmVxdWlyZW1lbnQuCjEuIFN0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br clear="all">
<div><br>
</div>
<span class="gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">Regards,<br>
Konstantin Triger<br>
</div>
</div>
</blockquote>
</div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">Regards,<br>Konstantin Triger<br></div></div>