Skip to content

Repository files navigation

Functional Programming

A learning track through the core concepts of functional programming, each building on the previous.

Learning track

#ConceptDescription
1FunctionThe basic unit: pure vs impure, total vs partial, declaration and application
2ImmutabilityValues that never change; persistent data structures and structural sharing
3Equational ReasoningReferential transparency, substitution model, and laws as rewrite rules
4CompositionCombining functions into new functions — the central mechanism of FP
5Higher-Order FunctionsFunctions as values; map, filter, flip, closures, and point-free style
6Currying & Partial ApplicationTransforming multi-argument functions; functions as results
7Algebraic Data TypesProduct types (AND), sum types (OR), pattern matching; the shape of FP data
8Newtype / Wrapper TypesType-safe wrappers with zero runtime cost; alternative instances; phantom types
9Type ClassesAd-hoc polymorphism: contracts, instances, laws, and dispatch by type
10Lazy EvaluationThunks, non-strict semantics, infinite structures, and eager vs lazy trade-offs
11Semigroup & MonoidAssociative combination of values; the algebra behind fold and mconcat
12Property-Based TestingLaws as universal properties; QuickCheck / Hypothesis / fast-check; shrinking
13FunctorLifting a function to work inside a wrapped type with fmap
14Natural Transformations∀ a. F a → G a; parametricity gives the naturality law for free
15ApplicativeApplying wrapped functions to wrapped values; combining independent effects
16FoldReducing a collection to a value; map, filter and more as folds
17TraversableEffectful mapping that preserves shape; swapping container and effect
18Continuation Passing StyleCPS transform, callCC, and the bridge from direct style to the Cont monad
19MonadSequencing effectful computations; solving the fmap nesting problem
20ComonadCategorical dual of monad; extract/extend; streams, Store, Game of Life
21Monad TransformersStacking monads to combine multiple effects in one computation
22Composing EffectsMonad Transformers, Free Monad, and Algebraic Effects compared
23Tagless FinalTypeclass-polymorphic programs; capability control; Free Monad alternative
24Concurrency and Parallelismpar/pseq, STM, async tasks, actor model — FP's lock-free concurrency story
25Profunctordimap; Strong→Lens, Choice→Prism; profunctor optics unify all optic kinds
26Arrowsarr/>>>/first; Kleisli; stream processors, FRP, parser combinators
27Lens / OpticsComposable, first-class access and update of nested immutable data
28Recursion SchemesGeneralised folds: cata, ana, hylo and the base functor pattern
29Codata and CoinductionDual of ADTs; infinite structures (streams, comonads) as greatest fixpoints
30Observable EffectsThe effect spectrum from pure FP to physical hardware; side-channel attacks
31Computation Models and λ-Calculusλ-calculus, β-reduction, Church numerals, SKI, Y/Z combinators

Diagrams

Each chapter's diagrams live in a sibling folder of the same name as the chapter, alongside the .md page itself. For example, docs/19-monad.md is accompanied by docs/19-monad/ which contains every D2 and SysML v2 source plus the generated SVGs for that chapter. The same convention applies under docs/monads/ and docs/optics/. See specs/diagrams.md for the diagram conventions in detail.

Monad catalogue

Each monad has a detailed page with type, bind semantics, motivation, diagram, and code examples in all nine languages.

MonadEffect modelledDetail
Maybe<a>optional value / silent failuremaybe.md
Either<e, a>failure with an error valueeither.md
List<a>non-determinism / multiple resultslist.md
IO ainput/output side effectsio.md
State s astateful computationstate.md
Reader r aread-only shared environment / configreader.md
Writer w aaccumulated log / output alongside a resultwriter.md
Parser aconsuming input; parsing as sequenced effectsparser.md
Cont r afirst-class continuations; callCCcont.md
STM aatomic transactions over shared mutable statestm.md
Prob adiscrete probability distributionsprob.md

Combining multiple monads into one computation: 21. Monad Transformers

Optics catalogue

Each optic has a dedicated page with type, laws, motivation, and code examples in all nine languages.

OpticEffect modelled
IsoLossless, reversible conversion between two types
LensFocus on exactly one field of a product type
PrismFocus on one constructor of a sum type
TraversalFocus on zero or more elements; read and write
FoldFocus on zero or more elements; read only
Getter / SetterRead-only (derived values) and write-only optics

Overview and composition rules: 27. Lens / Optics

Category Theory track

A parallel math-first track explaining the categorical origins of the FP abstractions above. Each page defines a CT concept precisely, maps it to its FP programming analog, and links to the corresponding chapter in Bartosz Milewski's Category Theory for Programmers (CTFP).

Pages contain no per-language code — for code examples follow the links into the FP track.

CT ConceptOne-line summaryFP Analog
CategoryObjects, morphisms, composition, identityTypes & functions; composition
Types & FunctionsHask as a categoryAll of functional programming
Product & CoproductUniversal pairing and choiceProduct types & sum types
FunctorStructure-preserving map between categoriesFunctor / fmap
Natural TransformationMorphism between functorsPolymorphic functions F a → G a
AdjunctionUniversal relation between two functorsCurry/uncurry; monad derivation
MonadMonoid in the category of endofunctorsMonad / >>= / return
F-AlgebraAlgebras for an endofunctor; initial algebraRecursion schemes: cata, ana

Full catalog, reading order, and CTFP source index: ct/README.md

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages