The expression problem describes a fundamental challenge in programming language design where adding both new data types and new operations to an existing system requires modifying existing code, violating the open-closed principle. Object-oriented languages make it easy to add new types but difficult to add operations, while functional languages have the opposite problem. The article explores solutions including the visitor pattern in C++, multiple dispatch in Clojure using multimethods and protocols, demonstrating how different programming paradigms approach extensibility differently.

20m read timeFrom eli.thegreenplace.net
Post cover image
Table of contents
A motivating exampleThe expression problem in functional programmingThe expression problem matrixA historical perspectiveFlipping the matrix with the visitor patternExtending the visitor patternSolving the expression problem in ClojureIs multiple dispatch necessary to cleanly solve the expression problem?Another Clojure solution - using protocolsSmall interfaces are extensibility-friendly

Sort: