Hacker News new | ask | show | jobs
by durandal1 742 days ago
How they basically could not improve on tagged union enum types as you express them in C is to me one of the misses. Modeling data through effortless sum types is a requirement for me when picking up a modern language.
4 comments

you're confused. zig had tagged unions since before 0.1.0.
I know, I'm saying they implementation they ended up with is terrible.
An earnest question: can you elaborate on what Zig got wrong in that respect?
I assume you mean algebraic data types as found in C#, Go (awkwardly), Rust, Swift, TypeScript, and Zig.

Also, gradual typing + ADTs: Crystal, Elixir and Erlang typespecs, Haskell, Python

Finally, dependent typing + ADTs: Ada 2012, Agda, Futhark, Idris, Lean

Since when does Go have algebraic data types? Like, even "awkwardly", I can think of nothing that even come close.
He might be referring to switching on the type of an interface... Not ADT for sure but I mean it's possible as a cludge as a tagged union, but it's more akin to single inheritance to be fair...
I don't think this was super important given the core goals of the project. I agree that effortless tagged unions are a very valuable feature in a language, but it's also one that is paradigm shifting and requires a different set of goals.

Without naming names, there is a language out there with some overlap with Zig's domain that does have really good tagged unions. But that project has a different set of goal than Zig's and that's okay. They're both good projects.