4 ms·
Yes. For example, from Standard ML: datatype 'a list = nil | :: of 'a * 'a list
by bmitc 3y ago
Yes. 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.