Re:Union types ('enum types') would be complicated in Go
by foldr on Monday December 09, 2024 @11:16AM
(#42367559)
You would want to layer some sugar on top to enable naming of the variants. I was just trying to keep my example as close as possible to valid Go code.
Even if you have to manually name the structs, you'd still have the benefit of exhaustivity checking in type switches, which you can't get with the (perfectly reasonable) approach that you mention.
Even if you have to manually name the structs, you'd still have the benefit of exhaustivity checking in type switches, which you can't get with the (perfectly reasonable) approach that you mention.