4 ms·
I believe this would work with type sets: type Result[T any, E any] interface { T | E }
by ibraheemdev 5y ago
I believe this would work with type sets:
type Result[T any, E any] interface {
T | E
}
- lmm 5y agoIf T=int32 and E=int32, does this behave like int32 | int32? If so, how can you tell which it is? (Presumably you have generic code that needs to know whether this case is T or E). If not, that's pretty surprising.
- yutijke 5y agoNo. T | E should only accept T or E. If their underlying type is int32 then int32 will not be accepted. If we want to accept underlying types then we would need ~T | ~E. Either way this doesn't help since typesets cannot be used as normal interfaces, only generic constraints.