Hacker News new | ask | show | jobs
by carlmr 1720 days ago
But in languages supporting this you do know that it's either A or B and you can use match expressions to deal with both cases.

Usually these are the languages with more focus on type safety, like OCaml, Haskell and Rust.

1 comments

To be fair, in OCaml, Haskell or Rust the type "A | B" also had to be declared beforehand.
Not exactly. For example, in Rust, you can do unions for traits: https://play.rust-lang.org/?version=stable&mode=debug&editio.... OCaml has the same system for its objects, where objects are structurally typed.
Yes, but it doesn't really change the way you could handle it, and what I wanted to point out is that it actually helps with type safety, enabling you to create total functions.