- Learning Functional Programming in Go
- Lex Sheehan
- 104字
- 2025-02-27 05:14:35
The expression problem
Different languages solve the expression problem in various ways:
- Open classes
- Multimethods
- Coproducts of functors
- Type classes
- Object algebras
The problem they solve is the same as what we looked at with our CarWithSpare example; It's all about how to add new functions over existing data types without having to recompile existing code and while retaining static type safety.
Go has rudimentary support for the expression problem. Type classes, object algebras, and so on. are not part of Go's standard library, but there's nothing stopping us from building any of the aforementioned solutions. Here's a great start: https://github.com/SimonRichardson/wishful.