3 ms·
They gave the reason for not including tagged unions that they overlap in confusing ways with interfaces. Not that the reasoning is correct or not. It was their
by entha_saava 6y ago
They gave the reason for not including tagged unions that they overlap in confusing ways with interfaces. Not that the reasoning is correct or not. It was their goal to make the language dead simple.
Now with the new generics proposal, it seems they have hacked up some crude closed interface types, which are something like union types. :/
- ithkuil 6y agoCan you make an example of how it would be confused with interfaces in weird ways?
- entha_saava 6y agoMaybe something like a union of struct type T and interface type I, but T also satisfies I. Then you have to specify some extra things / add features to keep it symmetric and being able to construct it both ways equally easily. GO Authors have a primary goal of Secondly, they think interfaces cover many of the need of variant types and they don't want some non-orthogonal feature.
- ithkuil 6y agoimagine an interface{} that can be annotated to say "you can only assign values ofItypes A, B and C to it. E.g. interface(A,B,C){} Since it's an interface{} it has no behaviour, the only thing you can do is a type assert / type switch. By extension, you could add some methods: interface(A,B,C){Foo(bool) int} This fails statically unless A, B, and C implement said interface. If they do, then this interface has exactly the same semantics as the normal Go interfaces, except that only types A, B and C can be assigned to it (and not type D even if it implements Foo(bool) int