Functional Programming: section map for agents
Main map · This map · Section overview
Notes on programming with pure functions and composition in Haskell and Scala, from evaluation and the functor-to-monad abstractions to errors, effects, streams, concurrency and testing in real programs.
All documents in this collection are listed below, grouped by subsection.
Status labels: Canonical = preferred starting point for its topic; Draft = provisional working material; Archived = preserved history. Unlabeled documents have no assigned status.
Building Functional Programs
How real programs are built from pure functions: errors as values, effect systems, ways to structure effectful code, streams, concurrency and parallelism, and property-based testing.
- Effect Systems: Haskell IO, Cats Effect and ZIO — Effects as values kept apart from their execution, built up from a toy IO to Haskell IO, Cats Effect 3 and ZIO, with a comparison of the three and a study order for the Scala effect libraries.
- Error Handling as Values — Errors as values instead of exceptions: totality, Option, Either and Try, fail-fast versus accumulating validation and why accumulation is applicative, typed errors in effect types, and converting at boundaries.
- Functional Concurrency and Parallelism — Parallelism versus concurrency in functional code: deterministic parallelism with strategies and the Par monad, Haskell threads, MVar, async and STM, fibers in Cats Effect and ZIO, and laws that keep parallel code equivalent to sequential.
- Functional Streams with fs2 and conduit — From lazy lists to effectful pull-based streams: why laziness gives modularity, why lazy I/O isn't enough, fs2, conduit and pipes, resource safety, backpressure and stream fusion.
- Property-Based Testing with QuickCheck and ScalaCheck — Testing with properties instead of examples in QuickCheck and ScalaCheck: pure generators, shrinking, where good properties come from, testing type-class laws, and why purity makes it easy.
- Structuring Effectful Functional Programs — Why monads don't compose and the ways around it: monad transformers, mtl-style classes, service handles and ReaderT, free monads, tagless final and ZIO layers, with their trade-offs and when to pick which.
Foundations of Functional Programming
The ideas the rest of the functional programming notes build on: purity and effects, evaluation and laziness, the lambda calculus, functions and composition, and recursion and folds.
- Evaluation and Laziness in Functional Programming — How functional programs are evaluated, from reduction, the substitution model and Church-Rosser to strict and non-strict semantics, thunks and sharing, space leaks, and call-by-name in Scala.
- Functions and Composition in Haskell and Scala — Functions as values in Haskell and Scala: lambdas and closures, returning functions for API design, currying and partial application, custom control structures, and composition into pipelines.
- Lambda Calculus for Functional Programmers — The lambda calculus as a programmer needs it: terms and binding, β-reduction, currying, reduction strategies, and Church encodings of booleans and numbers.
- Pure Functions, Referential Transparency and Effects — Referential transparency and where substitution breaks, side effects, immutability and persistent data structures, and the functional core with an imperative shell.
- Recursion and Folds in Functional Programming — Writing recursive functions with pattern matching and accumulators, map as abstracted recursion, foldr and foldl with their corner cases, Foldable, and combinators built from folds.
Functional Abstractions: Functor to Monad
The type-class abstractions of functional programming, from map and flatMap through functor, applicative, traversable and monad to monoids, polymorphism and category theory.
- Applicative Functors in Haskell — Applying functions that sit inside a functor with pure and <*>, applicative style for independent computations, how it differs from a monad, the laws, and the Maybe, list and ZipList instances.
- Category Theory for Functional Programmers — Why category theory is worth knowing for a programmer, how its standard constructions map onto types, functors and currying, purity and denotational semantics, natural transformations, and resources for learning it.
- Functors in Haskell — A functor as a computational context: the Functor class and fmap, kinds and type constructors, lifting, the functor laws, and instances including functions.
- Monads in Haskell and Scala — Monads as a way to glue functions into sequential computations, map, flatMap and for expressions in Scala, and the Option, Writer, State, Reader and IO monads, including what IO does and doesn't make pure.
- Semigroups and Monoids — Associative combination and the identity element: definitions, laws, examples and uses of semigroups and monoids, and why the identity matters.
- Traversable and traverse in Haskell and Scala — traverse, sequenceA and traverse_, how the chosen applicative decides between short-circuiting, IO effects, parallelism and state, writing instances, the laws, and the essence of the iterator pattern.
- Type Classes and Polymorphism in Haskell and Scala — Kinds of polymorphism and parametricity, type classes and their Haskell and Scala encodings compared with Java interfaces, higher-kinded types, GADTs, type-level programming with singletons, and tagless final.
- Understanding map and flatMap — What map preserves in a structure such as Option, the identity and composition laws behind it, and when the next step needs flatMap instead, with Scala examples.
Functional Programming Languages: Haskell and Scala
Language notes, ecosystems and learning resources for Haskell and Scala, the two languages the functional programming notes use.
- Haskell Language Notes and Resources — Haskell learning path, toolchain and ecosystem, standard library alternatives and a custom Prelude, useful libraries, language notes from GHCi to constructors, practical advice, and books, courses and other resources.
- Scala Language Notes and Resources — Scala language notes from expressions, classes, traits and variance to comprehensions, collections and implicits with their Scala 3 equivalents, plus the functional ecosystem, dependency injection, and books, talks and other resources.
Practice and Study in Functional Programming
Putting functional programming into practice: reading paths through the library, exercises and projects, refactoring examples, a dated study log, and links still to file.
- Functional Programming Exercises and Projects — Exercise collections for Haskell and Scala, specific problems on lists, trees, functors and applicatives, learning tasks, and project ideas from games to reference applications.
- Functional Programming Links to Sort — Unfiled functional programming links, open questions and todos, grouped by the note they should move to, from domain modelling and optics to Scala articles and the study plan.
- Functional Programming Reading Paths — Goal-ordered routes through the library for Scala, Haskell, functional application design and theory, followed by articles, books, courses, talks and blogs.
- Functional Programming Study Log — A dated study log from November and December 2023 covering folds and fusion, unfolds and origami programming, laziness and trees, traverse, continuation-passing style, monoids and monads.
- Refactoring Functional Code in Haskell — Refactoring examples in Haskell: splitting a Collatz step counter into separate jobs, replacing partial functions with types that carry the guarantee, and wholemeal programming.
Use the main map to explore other collections. Descriptions come from note metadata or the page summary; working notes and versions retain their own scope.