3 ms·
> For those that are well versed in type theory, what is the neatest solution to this in language design, if there is one at all? Row-polymorphism instead of
by consilient 3y ago
> For those that are well versed in type theory, what is the neatest solution to this in language design, if there is one at all?
Row-polymorphism instead of structural subtyping.
The idea is that instead of treating `Record<,>` as parameterized by two ordinary types, you parameterize it with a single type-level collection of key-value pairs, and then write functions which are generic over parts of that collection. So the equivalent of a typescript function that works fine over open records would look something like this `<Rest>(obj: { SomeRow, Rest }) => { SomeRow, Rest }`, whereas `(obj: { SomeRow }) => { SomeRow }` says you can't have any extra entries and `<Rest>(obj: { SomeRow, Rest }) => { SomeRow }` says you can have extra entries but they're getting thrown out.
This also lets you reuse machinery between records and sums more easily, since sums are also realizations of rows.
Purescript and OCaml have good row type support. You can also sort of hack it together in typescript if you're very very careful, but I wouldn't recommend it.