3 ms·
I was put off slightly at first by the name as well, not so much now. It is a generalization of the enums from the C languages. Also Enum seems a good name be
by sixbrx 13y ago
I was put off slightly at first by the name as well, not so much now. It is a generalization of the enums from the C languages.
Also Enum seems a good name because they represent fixed alternatives that may be (finitely) enumerated (We're saying "Let me enumerate the alternatives that this type may hold."). Whereas "union" seems to speak to its underlying implementation (which may or may not hold) as a tagged, overlapping union. Ie. that usage of union says much less about the intended semantics and is more of a possible implementation detail. Otherwise if you look at the actual meaning of "union" it doesn't seem to fit really. Maybe "sum" might be closer but again that's leaning towards the theoretical, and in that case you'd probably then need to rename struct to become "product" for symmetry.
- chongli 13y agoHey, I'd be all for having them called sum and product types. But then why not go full out and have (generalized) algebraic data types?