Description
The records proposal forbids empty records and records with a single entry:
A record may have only positional fields or only named fields, but cannot be totally empty. There is no "unit type". A record with no named fields must have at least two positional fields. This prevents confusion around whether a single positional element record is equivalent to its underlying value, and avoids a syntactic ambiguity with parenthesized expressions.
There has been discussion in the past of trying to exploit the symmetry between parameter lists and records. I'm slightly worried that this restriction may come back to bite us, since it prevents (e.g.) uniformly reifying argument lists as records. Is it possible to make this a restriction only on the literal syntax? That is, semantically we still have zero length and unary records, we just have no literal syntax for them?
As a second step (or an alternative step) we could now or in the future add alternative syntax that generalized fully. For example, I can imagine:
- Adding a static constant
Record.unit
onRecord
which is the unique zero length record. - Adding a unary constructor
Record.single
onRecord
which produces a unary tuple - Or generalizing fully and say that there is a "magic" n-ary constructor on
Record
such thatRecord(....)
produces the record corresponding to the literal record syntax(...)
, with the additional generality that...
may be empty or a single positional argument.
cc @munificent @lrhn @eernstg @natebosch @jakemac53 @stereotype441