Let's Start Functional
Learn functional programming by building a linear-time regular expression engine in Idris 2: test-first, step by step.
Functional programming has a reputation for being beautiful, powerful, and impossible to start: monad tutorials that explain burritos, type theory before "hello world". This book takes the opposite route. We are going to build one small, real, useful thing, a regular expression engine, and let every language feature earn its keep along the way.
By the last chapter you will have written, in Idris 2:
a complete regex engine with classes, escapes, and counted repetition, matching in a single left-to-right pass, immune by construction to the catastrophic backtracking that has taken down real services;
a parser-combinator library from scratch, in about a screen of code;
a machine-checked proof that part of your engine is correct: not tested on examples but proved, for every input;
a working lexer built on top of your engine, as a capstone.
Every feature starts with a failing test. The commit history of the repository is the tutorial: each step is a small red/green commit you can replay.
Who is this for?
You can program (in JavaScript, Python, Rust, Java, anything) and you are curious about functional programming. No Haskell, no category theory, no prior Idris knowledge required. If you have bounced off functional programming before, this book was written for you.
How to read
The chapters build on each other, so read them in order. Each one follows the same rhythm:
a question we cannot answer yet,
a failing test that pins the question down,
the smallest amount of code that answers it,
and a look at what the language just did for us.
Head to Why Functional? Why Idris? to begin.
Note
All the code lives at github.com/ubugeeei-prod/lets-start-functional. The
regex/directory is the engine, and every chapter's red/green steps are separate commits.