3 ms·
The enum example is not really a union though or is a constrained version. For example, the cases are non-recursive.
by bmitc 3y ago
The enum example is not really a union though or is a constrained version. For example, the cases are non-recursive.
- tialaramex 3y agoUm, what? You believe unions are recursive data structures?
- bmitc 3y agoYes. For example, from Standard ML: datatype 'a list = nil | :: of 'a * 'a list
- tialaramex 3y agoI have never seen this called a "union", and that's certainly not what people mean when they speak of a "tagged union".
- bmitc 3y agoWhat do you think tagged unions are? What languages are you referring to? F# calls these discriminated unions. OCaml calls them variants or tagged unions. https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/discriminated-unions https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref... https://ocaml.org/docs/basic-data-types#variants https://ocaml.org/docs/basic-data-types#variants
- tialaramex 3y agoHuh. I was thinking about this in much lower level terms, it seems weird to me to define these structures recursively when how they're actually stored is thus omitted yet that's actually crucial, but I guess if you work in a sufficiently high level system you don't care about the implementation details.
- louthy 3y agoIt is exactly what they are. ‘Tagged’ or ‘discriminated’ unions are a set of named product types - the name being the tag/discriminator.
- adamwk 3y agoSwifts enums can be recursive though as can rusts
- bmitc 3y agoThanks for the clarification. That does indeed make them closer to unions.