An Introduction to Recursion Schemes
summary
Live coding shows how list product and range move from loops to recursion then to cata and ana by factoring out the list into a type constructor F so the same code works for any recursion scheme. Uses Scala 2.13 unfold, a Cats-style Functor for F, and kind-projector-style types; exercises and solutions live on GitHub. Demonstrates composing cata and ana into a hylomorphism to implement factorial and frames quicksort as divide-and-conquer.
AI-written summary · about
chapters (19)
- 0:00Introduction and disclaimer
- 0:45Naive solution for list multiplication
- 2:12Implementing with folds
- 3:00Generating range with unfold
- 5:21Introducing recursion schemes
- 6:04Implementing foldRight
- 9:50Lazy foldRight solution
- 11:15Implementing unfold
- 12:41Generalizing foldRight and unfold
- 15:25Factoring out data structures
- 17:07Defining recursion scheme steps
- 19:43Unfold steps and terminology
- 21:30Introducing pattern functor
- 23:03Abstracting with higher-kinded types
- 24:56Using functors in recursion
- 26:29Final foldRight implementation
- 27:40Introducing cata and ana
- 29:09Composing cata and ana
- 30:18Quicksort with hylomorphism
