Re:Hexagonal Architecture vs. Free Monad
by headbee on Wednesday November 23, 2022 @05:05PM
(#33725114)
I had read this article more as a "from-first-principles" example, but it's a good note for people who might be unfamiliar with practical Haskell. Using an effects system also promotes the domain DSL from an initial-tagless language (only the interpreter is extensible) to a tagless-final language (both the language and the interpreter are extensible).
It may be worth noting that effectful, polysemy, and the other "new kids" of effects systems are not the only option: record-of-functions, mtl, and type-class effects aren't cutting edge, but they're a little more approachable from an OOP dependency injection pattern.
This lets you avoid having to write an interpreter for some particular ReservationExpr monad - instead, you specify individual effect handlers, then use them as you want. For example, we could write something like this:
What's even more fun is that you can actually interpose effects. So, I can write this: Being able to play around with handlers like this is really useful, both for testing and for adding on niceties to business logic.