3 ms·
I think maybe you are approaching this from the wrong perspective. Instead of asking what can I use sum types for, it might be useful to ask, what is the shape
by catlifeonmars 6y ago
I think maybe you are approaching this from the wrong perspective. Instead of asking what can I use sum types for, it might be useful to ask, what is the shape of existing data? As it turns out, most systems contain either implicit or explicit sum types. Take JSON, for example. A JSON value can be defined as sum type of null | boolean | number | string | Array<JSON> | Object<JSON>. Types are useful way of describing characteristics of domain you are working in.
- galaxyLogic 6y agoInterpreting JSON is a good concrete example. But I wonder if that hints at that sum-types are mostly good for writing interpreters (and compilers). Another good example mentioned is nullable types. It seems null is so important that many programming languages have built-in support for it. So it seems null-types make null unnecessary. (?) I can also see that sum-types are useful for modeling data. But are there any (relational or otherwise) databases which have support for sum-types?