logoalt Hacker News

Jtsummers • yesterday at 9:53 PM • 2 replies • view on HN

https://zig.guide/language-basics/unions/ - Seems like it's more similar to Ada's variant records: https://learn.adacore.com/courses/intro-to-ada/chapters/more...

Instead of just getting one type that includes the discriminant and records, Zig and Ada have a tag of some type whose value determines which variant is being used, and then the union (Zig) or record (Ada) is its own type.


Replies

slopinthebag • yesterday at 11:12 PM

why would you ever need them to be seperate?

➕ show 2 replies
knorker • yesterday at 10:48 PM

I still don't get it. Is it like a Rust enum, but worse, because you can accidentally only detect the problem at runtime?