-
Notifications
You must be signed in to change notification settings - Fork 224
Description
The proposal for tuples have a Record
class which acts as a common supertype of tuple types.
Whether that is necessary or desirable depends on perspective and features.
The main reason for separate types to have a shared supertype is either having a shared interface or other shared affordances.
For example function types have a common supertype Function
which abstracts over their ability to be called (they have a "dynamic call
" member), and people are asking for a supertype of enums, which have a shared int get index;
interface member.
So, the question is whether tuples should have any shared functionality, and if not, whether they should have a supertype anyway, for good measure.
The proposal suggests that the Record
class have methods which reflect on the tuple. Those work on all tuples, and only on tuples, and therefore need an argument type of Record
.
I would prefer to not add such functions outside of dart:mirrors
, and then they would be part of a RecordMirror
, not something which works on the reified tuple itself. If they exist outside of mirrors, the functions could also take any object as argument, and treat non-tupes as if they were one-tuples containing the value (I also argue that there should be no one-tuples because the product type T^1 is just T, so that would be consistent).
There is no other shared functionality between tuples, those two reflective functions are the only ones which work on tuples independently of the tuple "width"/"arity"/"structure". There is no shared interface members between (int, int)
and ({int x})
, so without those two method, there is no advantage in knowing that something is a tuple, because you still don't know which tuple structure it is (and there is a countably infinite number of those if you try to do an exhaustive search). You're better off casting to dynamic
if you want to explore the members of an arbitrary tuple, than by trying to cast to a tuple type.
If there are no empty tuples (or even no singleton-tuples), the Record
type also feels incomplete (to me). It's true that it contains all tuples, but with that view, maybe a single object is a one-tuple, so why is Object
not a subtype of Record
?
Still, people like to have categories and be able to express those categories in code. Saying that a variable is a Record r;
is documentation that is statically and dynamically enforced (whereas Object tuple;
is just text, no enforcement).
(Betteridge's law says no.)