Re:Why Reliability Demands Functional Programming
by cubefox on Sunday December 28, 2025 @04:36AM
(#46409750)
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.
Re:Why Reliability Demands Functional Programming
by jesse__ on Sunday December 28, 2025 @03:36PM
(#46414244)
Okay .. so, riddle me this Batman.
If I have an untagged union in <language_of_your_choice>, and I'm iterating over an array of elements of type `Foo|Bar|Baz`, and I have to do a dynamic cast before accessing the element (runtime typecheck) .. I believe that must actually be a tagged union under the hood, whether or not you call it a tagged union or not... right? ie. How would the program possibly know at runtime what the type of a heterogeneous set of elements is without a tag value to tell it?
Re:Why Reliability Demands Functional Programming
by cubefox on Monday December 29, 2025 @02:39AM
(#46418331)
That sounds plausible. Just like functional programming languages are imperative under the hood. It's all magic as far as I'm concerned.
Re:Why Reliability Demands Functional Programming
by jadsfwasdfsd on Sunday December 28, 2025 @10:42AM
(#46411845)
> 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.
Re:Why Reliability Demands Functional Programming
by cubefox on Sunday December 28, 2025 @11:52AM
(#46412397)
To be fair, even Wikipedia talks about "untagged unions" only in the context of C. The terminology is confusing and the literature often out of date.
Re:Why Reliability Demands Functional Programming
by jesse__ on Sunday December 28, 2025 @03:39PM
(#46414270)
I believe that, by the description provided, most languages that you're talking about must actually represent 'untagged unions' as tagged unions under the hood. See my sibling comment. I'm curious
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