The Expression Problem and its solutions (eli.thegreenplace.net)
recommended by 1 user | 2016 | 73 points by ingve | functional programming | original thread |
One user recommended this thread. What they said:
vogr Dec 17, 2019 | on: What's new in Java 12, 13 and 14 | context

I think the limitation you are describing is one of the two aspects of the expression problem[0]:

- with objects you can easily add new types, but it's difficult to add functions (methods) dealing with these types

- with sum types you can easily add new functions, but it's hard to add new variants in the sum type

Is it possible to overcome these limitations? I first read about the expression problem in the excellent post "The Expression Problem and its solutions"[1] on Eli Bendersky's blog (discussed here[2] on HN); as the title suggests it does present interesting ways to "solve" the expression problem.

However he also points out that the chosen solution in a a typical programming language (visitor pattern) quickly becomes unwieldy. The second solution (multimethods) is much nicer to deal with, but requires support from the language.

[0]: https://en.wikipedia.org/wiki/Expression_problem

[1]: https://eli.thegreenplace.net/2016/the-expression-problem-an...

[2]: https://news.ycombinator.com/item?id=11683379