> Actually, records are even better* than tuples. EP 395 says: > > Records can be thought of as nominal tuples. They are certainly not better, that's just a sad click-bait (the author even admits that). Sometimes nominal typing is better and sometimes structural typing is better. Forcing people to always use nominal types just ends in a lot of generic or long/meaningless names - one can already see this in Java.
I've been thinking about structural vs nominal. As you say, both have use cases. How would you combine both in one language so it's not confusing?
Think about the following type-level (not runtime) representation for a structural type (tuple):
(String -> Integer)
And the following for a structural type with where each "member" has a name: (("name" -> String) -> ("age" -> Integer))
And the following for a named structural type where each "member" has a name: ("User" -> (("name" -> String) -> ("age" -> Integer)))
The last structural type here would be equivalent to a class/record in Java. I would then add syntax that makes working with these special kinds of structural types more easy. So record User (String name, Integer age)
would translate to the structure above.
But one could also do something like that _if they wanted to_: ("User" -> (("field1" -> ("name" -> String)) -> ("field2" -> ("age" -> Integer))))
The closed equivalent would be a Java record where each member is annotated. This could be used to serialize/deserialize it into json.I think that's what I would try :) but I'm not a PL designer.