<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<font size="4" face="monospace">No, frozen arrays has nothing to do
with tuples. It has to do with making arrays safe to share
without need for copying and without fear of unexpected mutation.
<br>
<br>
(An array can have only a single component type, and the size is
only known to the dynamic type system, so while in theory an array
could be the backing store for any tuple, these tuples would be
very weakly typed -- you would have no ability to differentiate
"tuple of string and int" from "tuple of seven floats".)<br>
</font><br>
<br>
<div class="moz-cite-prefix">On 12/15/2024 10:16 AM, david Grajales
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CADFQZ76BDHbKtzhp6EayeuS7N3-6yLSq4JCsv3aN72KrTrOn1w@mail.gmail.com">
<p dir="ltr">I have been reading the JEP: Frozen Arrays<br>
<a href="https://openjdk.org/jeps/8261007" moz-do-not-send="true" class="moz-txt-link-freetext">https://openjdk.org/jeps/8261007</a></p>
<p dir="ltr">Wouldn't this be equivalent to python tuples in
practice? If so why don't just call it tuples so it's more
familiar with what most people already know for s tuple? </p>
<p dir="ltr">Or does it have some difference that scapes me or
does the amber team has a more richful feature in mind to be
called "tuple" in an hypothetical future?</p>
<p dir="ltr">Best regards!</p>
<br>
<div class="gmail_quote gmail_quote_container">
<div dir="ltr" class="gmail_attr">El sáb, 14 de dic de 2024,
8:51 a. m., Remi Forax <<a href="mailto:forax@univ-mlv.fr" moz-do-not-send="true" class="moz-txt-link-freetext">forax@univ-mlv.fr</a>>
escribió:<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_6872284408570940607zwchr">
<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>"Brian Goetz" <<a href="mailto:brian.goetz@oracle.com" target="_blank" rel="noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">brian.goetz@oracle.com</a>><br>
<b>To: </b>"Red IO" <<a href="mailto:redio.development@gmail.com" target="_blank" rel="noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">redio.development@gmail.com</a>><br>
<b>Cc: </b>"david Grajales" <<a href="mailto:david.1993grajales@gmail.com" target="_blank" rel="noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">david.1993grajales@gmail.com</a>>,
"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>Wednesday, December 11, 2024 6:27:13 PM<br>
<b>Subject: </b>Re: anonymous records as an
implementation for tuples in Java<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"><font face="monospace" size="4">I had thought my reminder
in the last reply would be sufficient, but again:
this is not the Java language design list, and "why
don't you just" proposals like this just distract us
from doing what we've actually prioritized.<br>
<br>
In the 30 seconds I could spare to look at your
idea, it seems to have all the same problems as the
C# anonymous class feature. <br>
<br>
As a side exercise, I invite you to ponder where
$TString-int lives, when classes in two separate
domains both use (String, int) and want to call each
other, and what could go wrong there. (But not on
this list.)</font></blockquote>
<div><br>
</div>
<div>Is it not the same issue as when you have a
deconstructor method in one class and a switch on it
in another class ?<br>
</div>
<div> <br>
</div>
<div> class Foo {<br>
</div>
<div> deconstructor (String s, int i) Foo { ... }<br>
</div>
<div> ...<br>
</div>
<div> }<br>
</div>
<div><br>
</div>
<div> Foo foo = ...<br>
</div>
<div> switch(foo) {<br>
</div>
<div> case Foo(String s, int i) -> ...<br>
</div>
<div> }<br>
</div>
<div><br>
</div>
<div>Rémi<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>
<br>
<div>On 12/11/2024 11:59 AM, Red IO wrote:<br>
</div>
<blockquote>
<div dir="auto">
<p dir="ltr">As tuples can be implemented entirely
as synthetic sugar I don't see the problem.
Simply desugar all denotations of the tuple type
to a structurally named type similar to arrays.
Then create 1 record definition for each used
type. (which I guess is at some point done for
arrays) <br>
Example:<br>
(String, int) foo() {<br>
return ("hi", 42);<br>
}<br>
void bar((String, int) tup) {<br>
System.out.println(tup.0 + tup.1);<br>
} </p>
<p dir="ltr">var x = foo();<br>
bar(x);</p>
<p dir="ltr"><br>
Becomes:</p>
<p dir="ltr">public record
$Tjava_lang_String-int(String e0, int e1)
extends Tuple {} </p>
<p dir="ltr">$Tjava_lang_String-int foo() {<br>
return new $Tjava_lang_String-int("hi", 42);<br>
} </p>
<p dir="ltr">void bar($Tjava_lang_String-int tup)
{</p>
<p dir="ltr">System.out.println(tup.e0() +
tup.e1()) ;</p>
<p dir="ltr">}</p>
<p dir="ltr"><br>
</p>
<p dir="ltr">var x = foo();<br>
bar(x);<br>
<br>
</p>
<p dir="ltr"><br>
</p>
<p dir="ltr">This is completely possible with
preprocessing alone. Syntax, descriptor format
and named vs unnamed elements are details not
worth the initial discussion. </p>
<p dir="ltr">I think tuples are great and require
no fundamentally new features to become part of
the language. </p>
<p dir="ltr"><br>
</p>
<p dir="ltr">Great regards</p>
<p dir="ltr">RedIODev </p>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, Dec 11,
2024, 17:23 Brian Goetz <<a href="mailto:brian.goetz@oracle.com" target="_blank" rel="noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">brian.goetz@oracle.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div> <font size="4" face="monospace">Yes, this
is one of those ideas that sounds good for
the first few minutes. (C# has explored
something similar with what they call
"anonymous classes", which turned out to be
mostly disappointing.)<br>
<br>
The problem is _linkage_. It's easy to
write out the creation expression:<br>
<br>
var tuple = (int id: 10, String name:
"foo")<br>
<br>
So now: what's the type of `tuple`? What
can I assign it to? How do I extract the
members? How do I write a method that
accepts a tuple of (int id, String name)?
What if someone passes it a tuple of (int x,
String s)? What does equals and hashCode do
on these things? These things have many
potential answers, but none of them are very
satisfying.<br>
<br>
If you're going to create a tuple,
presumably someone wants to consume it,
store it somewhere, extract its components.
C#'s answer was that you can only do so
_within a compilation unit_ (effectively,
within the same class) because there was no
guarantee that one classes { x: 1, y: 2 }
was interoperable with another. <br>
<br>
Linkage in Java is nominal; when you call a
method `m("foo")`, the caller and
declaration have to agree on the types, and
the method descriptor (in this case,
`(Ljava/lang;String;)V`) is recorded in the
classfile. if you want to be able to pass a
tuple to a method, we have to record
something, and that means either inventing a
whole new structural type system to ensure
that tuples of the wrong type don't get
exchanged, or erasing everything to some
"Tuple" class (in which case you lose names
and likely types of components.) <br>
<br>
DISCLAIMER: this is not meant to be a
canonical explanation of why we can't have
it. It is literally the first 30 seconds of
stuff off the top of my head about why this
is more complicated, from the perspective of
how the language holds together, than it
looks.<br>
<br>
Essentially, this doesn't really give you
the expressive power people want from
tuples; what it gives you is a convenient
syntactic shorthand for packing the elements
into a blob. Which makes it a fairly weak
feature, and one where, once we had it,
people would immediately see its weaknesses
and then want more. So it is not any kind
of shortcut; it is mostly convincing
ourselves that concise creation syntax is
the only important thing we get from
tuples. But I don't think that's a good
idea.<br>
<br>
I would put this problem in the same bucket
as "collection literals" -- optimized
syntactic forms for common structural shapes
such as lists. This is on our radar but
there are a number of higher-priority things
ahead of it, so we won't be talking about it
for a while.<br>
<br>
<br>
</font><br>
<br>
<div>On 12/11/2024 10:58 AM, david Grajales
wrote:<br>
</div>
<blockquote>
<div dir="ltr">
<p style="color:rgb(0,0,0)"><font face="arial, sans-serif">I've noticed
that the topic of tuples in Java has
come up recently, and I wanted to take
this opportunity to show an idea
regarding the use of<strong>"anonymous"
records</strong>as a potential
implementation for tuples.</font></p>
<p style="color:rgb(0,0,0)"><font face="arial, sans-serif">The idea
would be to create<strong>ad-hoc
records</strong>on the fly for short
lived methods, which don’t have a
formal name but are defined by their
components. For example, imagine
something like this:</font></p>
<p style="color:rgb(0,0,0)"><font face="arial, sans-serif"><span>var</span><span>tuple</span><span>=</span>(<span>int</span>id:<span>10</span>,
String name:<span>"name"</span>);<br>
</font></p>
<p style="color:rgb(0,0,0)"><font face="arial, sans-serif">This would
allow us to create simple, unnamed
records with specified fields for
quick, on-the-fly usage. Accessing
values from the tuple could then work
like this:<br>
</font></p>
<p style="color:rgb(0,0,0)"><font face="arial, sans-serif">var myTupleId
= <a href="https://urldefense.com/v3/__http://tuple.id__;!!ACWV5N9M2RV99hQ!JWvS3-XRXfU_BDrdY-5L5h1ddl_PStJP3vNDQtkLvrxFIdBwPvzjEW-LMmG4r8MykbGgC-Y4e8oBmPElPpwijXdqZiO2$" rel="noreferrer noreferrer" target="_blank" moz-do-not-send="true">tuple.id</a>()</font><br>
</p>
<p style="color:rgb(0,0,0)">for passing
them as arguments to methods it could be
something like this. </p>
<p style="color:rgb(0,0,0)">void
foo(Tuple<Integer, String>
tuple){} </p>
<p style="color:rgb(0,0,0)">The idea is
that, as records are just classes with
special constraints to force invariants,
tuples could be records with special
constraints, for example as they would
be meant to be created on the fly for
pin point needs, they should not have
validation in the constructor or
overriding of getters, but they would
still get automatic<code>equals()</code>,<code>hashCode()</code>,
and<code>toString()</code>methods.<font face="arial, sans-serif"><br>
</font></p>
<p style="color:rgb(0,0,0)"><br>
</p>
<p style="color:rgb(0,0,0)">I don't know
how problematic or bad this approach
would be if there were plans to ever
introduce construct tuples to Java.</p>
<p style="color:rgb(0,0,0)">best regards.</p>
</div>
</blockquote>
<br>
</div>
</blockquote>
</div>
</blockquote>
<br>
<br>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>