Pexels Photo 356079

Free monad or tagless final? How not to commit to a monad too early by Adam Warski

Pexels Photo 356079

Monads are everywhere!

However, choosing a particular monad may obscure business logic but there is a way to solve this and Adam Warski showed us how at ScalaIO.


Free monad or tagless final? How not to commit to a monad too early

Functional programming is on the rise; monads are everywhere. But how to choose the right wrapper for the values which we manipulate (i.e. monad)? Quite often, the answer is far from obvious, and it’s useful to delay the decision as much as possible. Furthermore, picking a particular monad too early might only obscure important business logic details. 
There are (at least) two ways to solve the problem, which are quite popular: free monads and the tagless final encoding. Both are equivalent in expressive power, but are radically different when it comes to code. 
In this live-coding talk we’ll see how to transform a simple application which relies on Futures into more generic forms, using either the free monad or tagless final. We’ll see how these two representations compare in terms of boilerplate, readability, composability and stack-safety. We’ll also discuss which approach might be a better fit for selected use-cases.
This talk was given by Adam Warski at ScalaIO