3 ms·
enums/sum type functionality could be implemented using Interfaces in golang.
by stcredzero 7y ago
enums/sum type functionality could be implemented using Interfaces in golang.
- akavi 7y agoNo, they can't. At least not in a type-safe way.
- stcredzero 7y agoJust define an Interface which includes the implementation of thisIsMySumTypeAsAnInterface() Then only types which implement that are in that Interface. There's your enum/sum type. Not ironclad, but safe enough to get things done.
- stouset 7y agoIt also doesn't actually accomplish what people are talking about using sum types for. There's also no language support for ensuring you've exhaustively matched every variant.