3 ms·
I’m pretty sure that’s an interface union, not a sum type. That said, you could definitely do an option type using interfaces, but it would be less efficient th
by jchw 5y ago
I’m pretty sure that’s an interface union, not a sum type. That said, you could definitely do an option type using interfaces, but it would be less efficient than pointers directly because of the itab overhead.
- tsimionescu 5y ago> I’m pretty sure that’s an interface union, not a sum type. It's a kind of sum type, but it can only be used to constrain types for a generic parameter. That is, you can define `func foo[T StaticOptional[int]](x T)` and then call it as `foo(StaticNone{})` or `foo(StaticSome[int]{123})`, but you can't do `func foo() StaticOptional[int]` or even `func foo[T StaticOptional[int]]() T {return StaticNone{} }`.
- jchw 5y agoI think that still eats the itab penalty so as long as the structures wind up with the same gcshape? But now I wonder.