Re:Union types ('enum types') would be complicated in Go
by wbl on Saturday December 07, 2024 @12:36AM
(#42347531)
The zero would obviously be the zero value of one of the constituents. Coproducts in most of Go are easy: it's interfaces that make it hard.
[ Parent
| on HN ]
Re:Union types ('enum types') would be complicated in Go
by masklinn on Saturday December 07, 2024 @02:48AM
(#42348024)
> The zero would obviously be the zero value of one of the constituents.
If interfaces are used for union types then the obvious zero is nil, not any constituent. Nil is the zero value of interfaces.
It’s perfectly consistent and in line with the rest of the langage.
Re:Union types ('enum types') would be complicated in Go
by wbl on Monday December 09, 2024 @03:53PM
(#42370452)
It's not clear to me that that would satisfy the categorical properties of coproduct that are wanted.
Re:Union types ('enum types') would be complicated in Go
by foldr on Tuesday December 10, 2024 @04:19AM
(#42375189)
Nobody cares about the categorical properties of the coproduct. But in any case, there's no theoretical issue here, since it would be just as if every enum had a 'Nil' variant implicitly defined.