logoalt Hacker News

jesse__yesterday at 6:51 AM2 repliesview on HN

The String|null example is just a nullable type; it's not an interesting use of unions either way. The conversation starts when it's Foo|Bar|Baz

I'm unfamiliar with typescript, so in that language I don't have an opinion either way, but in C, you pretty much always want the tag


Replies

jadsfwasdfsdyesterday at 3:42 PM

> but in C, you pretty much always want the tag

We aren't discussing unions in memory layout, but in type systems. This also clearly indicates you aren't qualified for this discussion.

show 2 replies
cubefoxyesterday at 9:36 AM

C doesn't support any untagged unions (or intersections) in the modern sense. In a set-theoretic type system, if you want to call a method of Foo, and the type of your variable is Foo|Bar|Baz, you have to do a type check for Bar and Baz first, otherwise the compiler won't compile.

show 1 reply