10 ms·
Genuine question—why would you need a sum type in a self-describing data format?
by the_girabbit 5y ago
Genuine question—why would you need a sum type in a self-describing data format?
- valenterry 5y agoWell, there are already sumtypes, just only specific builtin ones, not custom ones. E.g. booleans are sumtypes (true | false). Everything else that is nullable is also a sumtype (e.g. number | null). I think it should be pretty obvious how these are helpful and why they are needed no?
- the_girabbit 5y agoYeah, but it’s a schema-less, self-describing data format. It’s not like a specific position in a data stream has a requirement to be a specific type. I can see why sum types would be useful in a schema or for the elements of a collection that is required to be homogeneous (ie. List<Foo|Bar>). For what use case would one use custom sum types in a schema-less data format?