4 ms·
Implementing sum types in a language that doesn't support them is so common that it has a name: the visitor pattern. Somewhat interestingly the visitor pattern
by deredede 3y ago
Implementing sum types in a language that doesn't support them is so common that it has a name: the visitor pattern.
Somewhat interestingly the visitor pattern is even useful in languages that have sum types as it makes it easier to implement generic traversals!
- contravariant 3y agoI wish having a polymorphic return value was more standard though. It always feels iffy to make a visitor that needs to keep an internal state in order to return anything.