- cross-posted to:
- typescript@programming.dev
- cross-posted to:
- typescript@programming.dev
I think object algebras have huge potential to improve the way complex software is written but I’ve never seen them used in practice. I think one reason why is that the research paper which introduced them is pretty hard to read. This post is my attempt to change that.
I’ve been working on this post off and on for like two years so I’m really excited to share it with people. It is very long. There’s a lot of ground to cover.
Your post only showed adding functionality over the algebra, not new types on which the algebra operates (or “sorts”, as they are otherwise known). In other words, you can’t easily extend
Expr
to support Boolean logic in addition to addition itself. For a concrete example, how could you represent ternary operators like in the expression2 + 2 == 4 ? 1 : 2
, such that it’s well typed and will never result in an exception? With GADTs, this is very simple to do: