Skip to content

Color-Of-Code/FP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

110 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Functional Programming

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

Learning track

# Concept Description
1 Function The basic unit: pure vs impure, total vs partial, declaration and application
2 Immutability Values that never change; persistent data structures and structural sharing
3 Equational Reasoning Referential transparency, substitution model, and laws as rewrite rules
4 Composition Combining functions into new functions — the central mechanism of FP
5 Higher-Order Functions Functions as values; map, filter, flip, closures, and point-free style
6 Currying & Partial Application Transforming multi-argument functions; functions as results
7 Algebraic Data Types Product types (AND), sum types (OR), pattern matching; the shape of FP data
8 Newtype / Wrapper Types Type-safe wrappers with zero runtime cost; alternative instances; phantom types
9 Type Classes Ad-hoc polymorphism: contracts, instances, laws, and dispatch by type
10 Lazy Evaluation Thunks, non-strict semantics, infinite structures, and eager vs lazy trade-offs
11 Semigroup & Monoid Associative combination of values; the algebra behind fold and mconcat
12 Property-Based Testing Laws as universal properties; QuickCheck / Hypothesis / fast-check; shrinking
13 Functor Lifting a function to work inside a wrapped type with fmap
14 Natural Transformations ∀ a. F a → G a; parametricity gives the naturality law for free
15 Applicative Applying wrapped functions to wrapped values; combining independent effects
16 Fold Reducing a collection to a value; map, filter and more as folds
17 Traversable Effectful mapping that preserves shape; swapping container and effect
18 Continuation Passing Style CPS transform, callCC, and the bridge from direct style to the Cont monad
19 Monad Sequencing effectful computations; solving the fmap nesting problem
20 Comonad Categorical dual of monad; extract/extend; streams, Store, Game of Life
21 Monad Transformers Stacking monads to combine multiple effects in one computation
22 Composing Effects Monad Transformers, Free Monad, and Algebraic Effects compared
23 Tagless Final Typeclass-polymorphic programs; capability control; Free Monad alternative
24 Concurrency and Parallelism par/pseq, STM, async tasks, actor model — FP's lock-free concurrency story
25 Profunctor dimap; Strong→Lens, Choice→Prism; profunctor optics unify all optic kinds
26 Arrows arr/>>>/first; Kleisli; stream processors, FRP, parser combinators
27 Lens / Optics Composable, first-class access and update of nested immutable data
28 Recursion Schemes Generalised folds: cata, ana, hylo and the base functor pattern
29 Codata and Coinduction Dual of ADTs; infinite structures (streams, comonads) as greatest fixpoints
30 Observable Effects The effect spectrum from pure FP to physical hardware; side-channel attacks
31 Computation 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.

Monad Effect modelled Detail
Maybe<a> optional value / silent failure maybe.md
Either<e, a> failure with an error value either.md
List<a> non-determinism / multiple results list.md
IO a input/output side effects io.md
State s a stateful computation state.md
Reader r a read-only shared environment / config reader.md
Writer w a accumulated log / output alongside a result writer.md
Parser a consuming input; parsing as sequenced effects parser.md
Cont r a first-class continuations; callCC cont.md
STM a atomic transactions over shared mutable state stm.md
Prob a discrete probability distributions prob.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.

Optic Effect modelled
Iso Lossless, reversible conversion between two types
Lens Focus on exactly one field of a product type
Prism Focus on one constructor of a sum type
Traversal Focus on zero or more elements; read and write
Fold Focus on zero or more elements; read only
Getter / Setter Read-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 Concept One-line summary FP Analog
Category Objects, morphisms, composition, identity Types & functions; composition
Types & Functions Hask as a category All of functional programming
Product & Coproduct Universal pairing and choice Product types & sum types
Functor Structure-preserving map between categories Functor / fmap
Natural Transformation Morphism between functors Polymorphic functions F a → G a
Adjunction Universal relation between two functors Curry/uncurry; monad derivation
Monad Monoid in the category of endofunctors Monad / >>= / return
F-Algebra Algebras for an endofunctor; initial algebra Recursion schemes: cata, ana

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors