4 ms·
> But they decided not to add enums because it conflicted and overlapped too much with interfaces. I'm very curious now about how it might conflict and/or over
by lelanthran 3y ago
> But they decided not to add enums because it conflicted and overlapped too much with interfaces.
I'm very curious now about how it might conflict and/or overlap with interfaces.
To reach the goal of an enumeration type (and all the strong type-checking that that brings with it), enums could look as simple as:
type DayNames enum {
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
}
...
func isFunDay (dow DayNames) {
// This must fail to compile, because there is an unhandled enumeration
switch {
case Sunday: ...
case Monday: ...
case Tuesday: ...
case Thursday: ...
case Friday: ...
case Saturday: ...
}
...
}
...
isFunDay (0) // Compile failure
var x int
isFunDay (x) // Compile failure
And I don't see how that conflicts or overlaps with interfaces.
- jurschreuder 3y agoI think something like when a variable type in an enum was an interface it would destroy the galaxy or something, not 100% sure, would have to look it up... 1 sec. Here you Go: https://go.dev/doc/faq#variant_types https://go.dev/doc/faq#variant_types
- lelanthran 3y ago> I think something like when a variable type in an enum was an interface it would destroy the galaxy or something, Hah :-) > Here you Go: https://go.dev/doc/faq#variant_types https://go.dev/doc/faq#variant_types Not quite the same: Variants are a constrained list of types. Enums are a constrained list of values. Let's assume that I agree with the reasoning for not having a constrained list of types. It still doesn't tell me why we can't have a constrained list of values.