> 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?
The good old missing sum type story.
Don't Rust, Haskell, Elm, Kotlin (with sealed classes), etc also have them?
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
But I felt similarly when I picked up Haskell coming from Ruby and Java, so I can understand the attitude. :D
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).
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.
}
}