First published at 21:12 UTC on March 28th, 2019.
Functional programming in the mathematical spirit.
Long and difficult, yet boring explanations given in excruciating detail.
Start by reading the slides, go through the worked examples and exercises. Watch the video when you cannot fully understan…
MORE
Functional programming in the mathematical spirit.
Long and difficult, yet boring explanations given in excruciating detail.
Start by reading the slides, go through the worked examples and exercises. Watch the video when you cannot fully understand something in the slides.
This part covers slides 1 to 11.
Chapter 11: Computations in a functor context III. Monad transformers
Combining Future and Option as an example of combining monadic effects "by hand" (without transformers)
Deriving the desired laws for lifting monads into a combined monad
Difficulties in combining monads in general: what does and what does not work
Examples of monads that compose and that do not compose with other monads
Simplifying the two identity laws of a monad into a single identity law for "lifting"
Deriving the composition law for "lifting" in terms of `flatten`, `flatMap`, and in terms of the Kleisli composition
Definition of "monadic morphism" and a proof that monadic morphisms are always natural transformations
Monad transformers as a way of reducing the programmer's work as opposed to combining monads by hand
What is a "monad transformer stack" and how it is different from a stack of nested type constructors
Formal requirements for a monad transformer: it must have two "liftings" and two "runners"
First examples: the monad constructions that lead to monad transformers (EitherT, ReaderT, WriterT)
The "zoology" of monad transformers: to each monad its own
The list of all known monad transformer constructions: "composed-inside", "composed-outside", "recursive", "product", "contrafunctor-choice", "free pointed", and "irregular" (StateT, ContT, SelectorT, CodensityT)
Why the continuation monad (as well as Codensity) do not actually have a full monad transformer (they do not have one of the "liftings" and they do not have any "runners")
Slides: https://github.com/winitzki/talks/blob/master/ftt-fp/11-monad-transformers.pdf
Code examples: https://github.com/winitzki/scala-examples/t..
LESS