📝Expression Problem

tags
§ Programming Language

To which degree can your application be structured in such a way that both (1) the data model and (2) the set of virtual operations over it can be extended without the need to modify existing code, without the need for code repetition and without runtime type errors. —Mads Torgersen, “The Expression Problem Revisited”

  • Functional programming language make it easy to define new operation that apply to existing types (operation is one function defined in one place), but make it harder to add new types (sum types)—that requires modifying all functions that pattern-match on constructors

    • typeclasses help to solve the other side of the problem
  • With object-oriented languages, the problem is reversed. Adding new type is easy—all operations are implemented as methods inside class definition, but adding a new generic method requires implementing it in all classes.

    • Visitor pattern helps to solve the other side in OOP languages (but requires boilerplate)
  • Multiple dispatch seems to solve the Expression Problem

Backlinks