2 ms·
is there any further information on why Rust and other recent languages have started using `enum` to refer to sum types? I don't use Rust or TypeScript (edit: a
by adamrezich 3y ago
is there any further information on why Rust and other recent languages have started using `enum` to refer to sum types? I don't use Rust or TypeScript (edit: apparently TS doesn't have this, my memory is bad) or any of those languages and it's been very strange to see this redefinition occur
- randomdata 3y agoTypescript has actual enums. They behave just like Go's (for better or worse). It's not clear why Rust got confused.
- adamrezich 3y agoyep, sorry about that, I misremembered TypeScript as having the same "kind of enums" as Rust.
- tubthumper8 3y agoTypeScript has discriminated unions if that's what you were thinking of https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions https://www.typescriptlang.org/docs/handbook/2/narrowing.htm...
- Quekid5 3y agoI think it might be due to the O'Caml influence on early Rust. They call them enums there[0]. [0] https://www.ocamlwiki.com/index.php?title=Enums_in_OCaml https://www.ocamlwiki.com/index.php?title=Enums_in_OCaml
- ReleaseCandidat 3y agoThey are called variants in OCaml (and inductive data types in Roqc). 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 https://discuss.ocaml.org/t/whats-up-with-ocamlwiki/13605
- Quekid5 3y agoAh, I see. That's sad :( ... 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...
- samatman 3y agoMy best guess is Java. 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.html 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.
- trealira 3y agoMaybe to appeal to C and C++ developers. Rust makes its syntax superficially similar to C/C++ syntax in many other ways: pointer/reference syntax, declaration of "struct" types, generic types using <T>, curly brace block structure, and the naming conventions enforced by their lints. To be fair, many of these traits of C and C++ are also copied by other programming languages (e.g. curly braces). But they could have gone in a different direction and had pointer and record syntax more like Pascal, or made a syntax more like OCaml, Standard ML, or Haskell.