Recently, I watched Jeff Bezancon’s talk titled “What’s Bad About Julia”. It’s an excellent talk. Towards the end, someone asks the question: “How much better or worse would the world be without union?”
I must admit, I was very surprised by this question: for me, union types are an unalloyed good.
I’ll invert this statement, and volunteer that languages that don’t have unions, and that lack statements (AKA modern languages!), and have strong typing - like Rust - are almost insufferable.
My primary gripe is with match statements consisting of, say, two “arms”. I now add a simple
println!() at the end of one of the arms - the code no longer type checks. (This in a match statement that wasn’t assigned to anything - I didn’t care about the return type.) I was quite annoyed at the compiler for not typing the match expression as
Union[Void, Foo], and forcing me to make the arms have matching type. It’s a fundamental weakness in Rust’s type system which is disproportionately felt by beginners in the language.
Finally I arrive at my question: I’m hoping the community, in a constructive spirit, can shed light on what this user may have been complaining about. Simply put, from a user perspective, how can unions be bad? (I realize they complicate the design of the language and implementation. I’m not talking about that - I’m talking about whether/how they make the language worse for users.)