by randomdata · 4y ago · 0 comments
Sum types are where you expect to find type safety. Some languages call sum types enums, which I expect is where the confusion lies. Neither Go nor C have sum types.
> literally every language which has constants has C-style enums
I think that ultimately that's a fair assertion, but one might argue that the definition does imply some kind of defined set. Both C and Go define syntax for characterizing enums in an established set which the machine can determine where the set boundaries lie. A language with only constants relies on human interpretation of what defines the set.
> For instance Java enums are not sum types, but are a type-safe, closed, set of values.
That's a sum type, also known as a tagged union. Neither Go nor C has those, as has been established multiple times now.