3 ms·
> only Odin, F#, OCaml and Zig have [Tagged Unions or Discriminated Unions] The good old missing sum type story. Don't Rust, Haskell, Elm, Kotlin (with sealed
by cies 2y ago
> only Odin, F#, OCaml and Zig have [Tagged Unions or Discriminated Unions]
The good old missing sum type story.
Don't Rust, Haskell, Elm, Kotlin (with sealed classes), etc also have them?
- squeegee_scream 2y agoI got to this part of the article and concluded it wasn’t worth my time, nor probably anyone else’s 1. Absurd claim that file names aren’t important in a stack trace 2. Claims they’re sharing a feature of F# that is never used, then later reveals they’ve been studying F# for 3 months 3. Then this statement about tagged unions
- Dansvidania 2y agobit of a weird article to find on the top of HN, to be sure.. But I felt similarly when I picked up Haskell coming from Ruby and Java, so I can understand the attitude. :D
- do_not_redeem 2y ago3 months, and he's already deep in acronym soup touting DDD, CDD, TDD, and TST. I'm getting major architecture astronaut vibes.
- johnnyjeans 2y agoMost languages have them, or allow them to be expressed. The name "Tagged Unions" literally comes from C.
- AnimalMuppet 2y agoDid it? Didn't Pascal have tagged unions?
- johnnyjeans 2y agoI looked it up and apparently it actually comes from Algol, but I digress. Point being sum types and their equivalents are found all over the place. I wouldn't be surprised to find out modern prologs have them.
- cies 2y agoJust having sum types is not enough: you need some level of type safety and exhaustivity checking in match/switch statements to truly benefit from them. Go does not. Java did not (maybe now with sealed types and exhausitvity checks on switch statement, but not sure if they've already landed).
- cempaka 2y agoJava does have exhaustiveness checking on switch expressions over sealed types in the release JDK, but not switch statements (due to the requirement for backwards compatibility). I'll often find myself writing var _ = <some switch>; to get around this, a very Java idiom if ever there was one, heh
- za3faran 2y agoJava does have exhaustiveness checking on switch statements for sealed types, but not enums (for backward compatibility), which is probably what you're using. Try this: sealed interface Shape permits Circle, Rectangle { } record Circle(double radius) implements Shape { } record Rectangle(double length, double width) implements Shape { } void test() { Shape shape = new Circle(5); switch (shape) { case Circle _ -> System.out.println("Circle"); case Rectangle _ -> System.out.println("Rectangle"); // Comment out this line to get an error. } }