3 ms·
I have never used golang but from my reading of the type parameters proposal, it also includes an approximation of "Sum types". You can define an interface wit
by yutijke 5y ago
I have never used golang but from my reading of the type parameters proposal, it also includes an approximation of "Sum types".
You can define an interface with a closed set of types
type Number interface { float64, int64, ... }
Now, the value will be boxed, so you will not have no-allocation sum types but you can approximate boxed sum types with this I think.
- cube2222 5y agoApproximating closed sum types is easy already, by creating an interface with a stub private method and implementing it for all variants. Then it's not possible to implement it using a type outside of that package. The main thing that's lacking is compile time checks whether variant matching is exhaustive.