A roadtrip with monads: from MTL, through tagless, to BIO
summary
A simple Scala weather client is implemented (console I/O, config, cache, third‑party HTTP client) using typeclass abstractions so every effect is abstracted behind an F. Code uses monad transformer stack originally (ReaderT/StateT/EitherT over Task), then swaps to typeclasses: ApplicativeAsk/ApplicativeError/MonadState plus custom Console and Weather traits. Tests become trivial by providing fake instances. Benchmarks show the transformer stack is ~an order of magnitude slower; replacing State with Atomic and providing custom instances brings performance near imperative, with a pathological Throwable‑only instance giving another ~2x.
AI-written summary · about
chapters (15)
- 0:00Introduction to functional programming
- 1:02Why functional programming
- 2:46Functional programming basics
- 7:00Building a weather app
- 17:23The monad stack problem
- 19:09Monads do not compose
- 21:45Type classes to the rescue
- 26:42Error handling with type classes
- 27:49State and console abstractions
- 29:33Final program with constraints
- 31:18Performance of monad stacks
- 33:25Tagless final approach
- 34:53BIO for better performance
- 35:35Removing the error type
- 37:02Conclusion and next steps
related talks
39mA roadtrip with monads: from MTL, through tagless to BIO
33mGETTING MORE MILEAGE FROM YOUR MONADS WITH MTL
31mThe Eff monad, one monad to rule them all
44mIO monad & Error management: From Exceptions to Cats MTL
35mThe Functor, Applicative, Monad talk
24mUsing Monad Transformers without understanding them
26mUP YOUR MTL GAME WITH CLASSY OPTICS
42mMonads you already use without knowing it
