by randomdata · 2y ago · 0 comments
That's literally what enums are: A set of named constants.
You might be thinking of what is traditionally known as sum types, which some people have recently started calling enums[1]. Indeed, Go does not have sum types.
[1] Presumably because of Rust using the wrong term when specifying its sum types
[0] https://www.ocamlwiki.com/index.php?title=Enums_in_OCaml
But way more important: this OCaml wiki is an AI generated mess full of, well, bullshit. https://discuss.ocaml.org/t/whats-up-with-ocamlwiki/13605
... and now that you mention it, I do remember the variants terminology, esp. around the polymorphic variants feature. It's been 20+ years since I used OCaml, I'm afraid...
Edit: I guess if you've never seen that this is, uh, controversial. Or something. Anyway, Java enums are full-strength classes, look at the planet example here https://docs.oracle.com/javase/tutorial/java/javaOO/enum.htm...
This is more like a Rust enum than a C one, I think you'll find.
It's not clear why Rust got confused.
https://www.typescriptlang.org/docs/handbook/2/narrowing.htm...