3 ms·
Interfaces are (open) sum types. Or close enough for government work.
by dllthomas 10y ago
Interfaces are (open) sum types. Or close enough for government work.
- dragonwriter 10y agoYes, but Java (unless I missed a recent change) doesn't let you assign new interfaces to existing types, so short of either wrapping Lists and Ints in containers implementing a common interface and demanding that the input be in the wrapped form, that doesn't actually help.
- dllthomas 10y agoFaced with this problem, I would precisely wrap Lists and Ints in containers implementing a common interface and demand that the input be in that form (actually, the input is text right? so I'd parse it into that form - assuming I couldn't get away with just manipulating the textual representation). Note that in the genuine sum-type case you're wrapping, too.