A free monad turns primitive operations from an algebra into a composable value representing a program. The program can be stored, passed to functions, or created dynamically; a separate interpreter later gives it meaning. section 13.10 section 13.0
Free[F, A] is a recursive structure containing a value of type A beneath zero or more layers of F. Return and FlatMap generate the monad, while flatMap adds further layers and F defines the permitted interaction protocol. section 13.4.1
Use the structure in several related ways:
- Sequence primitive operations from an algebra into a program value. section 13.10
- Interpret a completed program into a target monad, including a specialized trampolined interpreter for Free[Function0, A]. section 13.4.1
- Combine free monads from different algebras into a unioned algebra, such as file and console operations. section 13.10
enum Free[F[_], A]: ... def run(using F: Monad[F]): F[A] = ??? @annotation.tailrec final def step: Free[F, A] = ???
Inspect the Free definition’s generic run method and tail-recursive step operation. section 13.4.1

