Talk:Tagged union

message: Uh, I suggest you reconsider your tagged union example for Pascal, not so much because of the Big-Brother implications of an Employee record tracking how many lovers someone has, which is merely bad from a legal and social point of view, but more because it has a serious logical flaw: it assumes that marriage and multiple lovers are mutually exclusive. This, of course, is fundamentally in error, making this a bad example of a tagged union, whose alternatives must be exclusive. Using code examples that demonstrate a significant misapprehension of one's problem domain only encourages buggy programming.
---
This is entirely true - I'll try and think of a better example. I was operating under the false assumption of 100% fidelity. It's a silly example anyway.
Derrick Coetzee 13:54, 4 Feb 2004 (UTC)
thread_title: Pascal

message: Can a set of C++ classes that inherit from a common base class, using a virtual method table to determine which (virtual) methods to call, be considered an example of a tagged union where the vtable pointer acts as the tag? --Damian Yerrick (talk | stalk) 18:54, 31 July 2007 (UTC)
replies: text: In short, yes, but with the limitation that you can't modify which subclass is used; this is fixed at creation time. Also, C++ classes can be implemented by means other than vtables; depending on the implementation the tag may be implicit. Dcoetzee 00:25, 1 August 2007 (UTC)
replies: text: You are saying that the tags are not mutable. This is the same behavior as in ML and other languages with algebraic data types. --Spoon! (talk) 05:26, 5 December 2007 (UTC)
thread_title:  Is a set of C++ classes similar to a tagged union? 

message: Union type currently talks about overlapped memory accessed through different types (untagged variants). This article says tagged unions are also called "variant, variant record, discriminated union, disjoint union, or sum type" but the ALGOL 68, Typed Racket, and Ceylon unions are tagged unions, but not sum types or any of these other terms. They're unions, where T ∪ T ≡ T, A ∪ B ≡ B ∪ A, and A ∪ B ∪ C ≡ (A ∪ B) ∪ C ≡ A ∪ (B ∪ C). Specsluce (talk) 23:08, 26 November 2014 (UTC)
thread_title:  ALGOL 68/Typed Racket/Ceylon union types 

message: I think Scala 3 union types should be mentioned somewhere, but if I understand correctly, they are neither union types nor tagged unions... Any ideas? — Chrisahn (talk) 18:46, 21 August 2022 (UTC)
thread_title:  Scala 3 union types 

message: Compiler tokens are the quintessential tagged union. I think using tokens as an example of tagged union would make this article more understandable. 50.206.176.154 (talk) 02:32, 5 March 2023 (UTC)
thread_title:  Compiler Tokens 

message: quote „ could take on several different, but fixed, types“ seems to be indicating that values created via different variants have to have different types. 
that is not true in all languages since some treat variants more like constructors of the same type.
the „different types“ requirement is probably coming from managed OO languages that use inheritance for the implementation of variants. 50.46.240.130 (talk) 06:28, 7 January 2024 (UTC)
replies: text:  Full quote: "A tagged union is a data structure used to hold a value that could take on several different, but fixed, types." The part "could take on several different types" refers to the value held in the union, not to the union type itself. The union type can remain the same, but the type of the value held in the union can vary. — Chrisahn (talk) 11:58, 7 January 2024 (UTC)
thread_title:  Different variants != different types