4 ms·
It's rather infuriating. An Enum is supposed to be just a Union of nullary constructors. What they're doing here is using the word Enum when they really ought t
by chongli 13y ago
It's rather infuriating. An Enum is supposed to be just a Union of nullary constructors. What they're doing here is using the word Enum when they really ought to mean Union.
This sort of overloading of language happens all over the place in programming and it leads to endless confusion. I find it extremely frustrating but what can I do about it?
- sixbrx 13y agoI 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?