6 Domain modeling with Free monads
This chapter covers
- Using Free monads to model business domains
- How to apply the Functor abstraction
- Getting familiar with some advanced type-level concepts such as GADTs
If you ask me, lifetimes are what distinguishes interface-like abstractions from genericity-like ones, such as functors, monoids, categories. There are many ways to generalize a data structure, but none of them bother about lifetimes. Generalizations don’t have a dimension of a lifetime because they are just timeless expressions over data structures. Generalizations focus on some properties and ignore others, they exhibit a math nature of a structure, but they don’t “work” in a common way. They rather “declare”. They just exist on the design time and on the compile time and mostly disappear after the program is compiled.
I would also state that only interface-like abstractions help us to handle complexity. Unlike generalizations, interfaces carry some meaning from a business domain, and their purpose is to give us the minimum of information needed for the tasks. No implementation details, nothing unrelated, nothing too abstract. Interfaces communicate the essence of that domain, and often they serve as documentation. Knowing your interface means knowing a part of your business domain, at least its public representation.
Figure 6.1 summarized the said:
Figure 6.1 Two sorts of abstractions