(Also see ticket #69, which talks about array data.)
Suppose there is a type t:
type t = { x: int, y: int, z: int }
The way to create an instance of this type now is with a structure initializer and appending the type at the end:
x = { x: 10, y: 20, z: 30 } : t
This syntax is nice because it provides a simple upgrade path for old code (just attach ": t") but not so nice because it's noisy and the type hides at the end, which is not true for nominal types, structural array types, or ES3-style function constructors.
Proposal: allow this syntax to be used:
new t(10, 20, 30)
if t is a structural record type. A new object tagged with the correct type is created and the values are assigned to its fields during initialization.
Points of argument:
- if there are values missing, what should we do?
- if there are too many values, what should we do?
- if values have to be converted for the assignment to work, what should we do?
IMO we should provide defaults if possible in the first case (give'm rope), ignore supernumerary values in the second (ditto), and fail in the third (since the current language requires no conversion, except between number types).