Free monads

In this chapter and the previous chapters, we represented sequenced computations with monads. The flatMap method of the monad describes how the computation steps should be joined and the function given to it as an argument—the computation step itself. The free monad elevates the concept of sequenced computations to the next level. 

First, we start to represent the computation steps as instances of some ADT (algebraic data type) of our choice. Second, we represent the monadic concept with instances of another ADT. 

To substantiate this approach, we can turn to the fishing example once again. Earlier, we had three actions we encoded as functions. These actions will be represented as value classes now. We also need to give specific ...

Get Learn Scala Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.