|
|
|
|
|
by randomdata
774 days ago
|
|
Enums produce values. Tag-only unions 'produce' types (without values). Realistically, there isn't a whole lot of practical difference. They were both created to try and solve much the same problem. As before, I posit that there is no need for a language to have both. You can do math on enum values, but that is of dubious benefit. In theory, tag-only unions provide type safety, whereas enums are just values so there is no inherit safety... But, as you probably immediately recognized a few comments back, with some static analysis you can take the greater view, type E int
const (
A E = iota
B
C
)
and invent something that is just as useful as proper type safety. All the information you need is there. So, in reality, that need not even be significant.But, technically there is a difference. Values and types are not the same thing. |
|
Source? Is this something that is widely accepted, or just how you think enums should be defined.
My understanding is you are saying (using c++ as an example since it has both types) an `enum` is a "true" enum, while an `enum class` somehow isn't?