News for hackers. Stuff that matters.
Re:Golang: How to Update APIs for Generics by yutijke on Thursday September 16, 2021 @05:59AM (#28549815)
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.

Re:Golang: How to Update APIs for Generics by cube2222 on Thursday September 16, 2021 @10:40AM (#28552415)
Approximating 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.