Re:Embedded Swift on the Raspberry Pi Pico
by bmitc on Wednesday March 06, 2024 @01:27AM
(#39612915)
The enum example is not really a union though or is a constrained version. For example, the cases are non-recursive.
[ Parent
| on HN ]
Re:Embedded Swift on the Raspberry Pi Pico
by tialaramex on Wednesday March 06, 2024 @08:15AM
(#39615607)
Um, what? You believe unions are recursive data structures?
Re:Embedded Swift on the Raspberry Pi Pico
by bmitc on Wednesday March 06, 2024 @08:22AM
(#39615677)
Yes. For example, from Standard ML:
datatype 'a list = nil | :: of 'a * 'a list
Re:Embedded Swift on the Raspberry Pi Pico
by tialaramex on Wednesday March 06, 2024 @08:31AM
(#39615745)
I have never seen this called a "union", and that's certainly not what people mean when they speak of a "tagged union".
Re:Embedded Swift on the Raspberry Pi Pico
by bmitc on Wednesday March 06, 2024 @09:04AM
(#39616059)
What 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-ref...
Re:Embedded Swift on the Raspberry Pi Pico
by tialaramex on Thursday March 07, 2024 @04:30AM
(#39626978)
Huh. 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.
Re:Embedded Swift on the Raspberry Pi Pico
by louthy on Wednesday March 06, 2024 @10:36AM
(#39617044)
It is exactly what they are. ‘Tagged’ or ‘discriminated’ unions are a set of named product types - the name being the tag/discriminator.