Well anyway, I diverged from that significantly now; Virgil has value types, tuples, ADTs, and closures and happily unboxes them all.
Well anyway, I diverged from that significantly now; Virgil has value types, tuples, ADTs, and closures and happily unboxes them all.
By now I also have my doubts that it will ever come, they should have had better inspiration from Modula-3/Eiffel/Oberon when Java was originally designed.
There's a bit of unnecessary overhead in having to externally declare and import the return type.
public [K key, V value] getElement(int index);
This really comes down to the dynamic vs typed argument, and to me the answer is "minimise the boiler-plate, maximise the guarantees.".But I wouldn't expect that to be the common use case - I'd generally expect that the caller would just be implicitly importing and using the type effectively declared in the method header.
var p: (int, int) = (0, 0);
var q = p.0 + p.1;
type Point(x: int, y: int) #unboxed { }
var p = Point(0, 0);
var q = p.x + p.y;
Both will generate identical machine code with no allocations. It requires no escape analysis or assumption of non-identity (both tuples and data types have structural equality).Right until there’s no more context than “this returns 2 elements” and you end up with 15 different Pair types and more verbosity for no value.
Named tuples are not better than tuples, they’re complementary, both are useful tools.
Not usefully so. If you’re splitting a collection in two, whatever context you add is almost certainly worthless overhead not worth the extra type.
[1] The two words even become separate, independent scalar values in the compiler IR. Thus the runtime support is minimal, in that it doesn't know anything about multiple-word values: the GC just needs to know whether a word is a reference or not.