Why the free Monad isn't free
summary
Argues the Free Monad isn't free: it defers evaluation by building an AST-like structure (trait Free with Return/Suspend/FlatMap), then evaluates via a generic interpreter using a runFree trampoline to swap stack for heap for stack safety. Shows a to‑do DSL, test interpreters (mutable map and action log) and a production interpreter returning Option. Costs are heavy boilerplate, large pattern-match interpreters, steeper learning curve and unclear runtime hit; alternatives include loops, built-in monads, or libraries like Scalaz/Cats/Doobie/Dubey.
AI-written summary · about
chapters (21)
- 0:00Introduction
- 1:47Outline
- 2:26Mono
- 5:33Composition
- 6:47Functors
- 7:11Monads
- 12:54Free Monad
- 16:39Why delay evaluation
- 17:54Trampolining
- 18:23The heap
- 18:48Function signature
- 21:24Writing an interpreter
- 24:00Using multiple interpreters
- 24:56Deferring side effects
- 25:37Blue Skies Scala
- 27:40Know your domain
- 30:14Sideeffects
- 32:23Practical use cases
- 33:02Other examples
- 34:11Kelleys experience
- 37:09Questions
related talks
19mFinding the Free Way
01h 14mBeyond Free Monads
32mDiscussion: Are Free Monads Really Free?
42mFunctional interpreters and you
43mFree monad or tagless final? How not to commit to a monad too early
27mMonad Stacks or: How I Learned to Stop Worrying and Love the Free Monad
36mDo it with (free?) arrows!
50mHierarchical Free Monads & Software Design in Functional Programming
