Chapters

What to Build Next

Combine what you have learned into a small verified program.

21.1 Suggested learning projects

You do not need to begin with a large theorem. Start with a small input space and explicit states and transitions; this makes the connection between programs and theorems easier to understand.

ProjectFirst implementationNext theorem
CounterIncrease and decrease a NatIt never falls below zero
Permission flagsSwitch between open and closedA closed state does not decrement
List reversalRecursive reverseReversing twice returns the original list
MaximumChoose by comparisonThe result is at least each input
Sortinginsert and sortSorted output with preserved elements

21.2 Break the problem into small parts

Develop in this order:

  1. Specification: State clearly in plain language what success means.
  2. Types and data: Describe possible states and inputs with enum and struct.
  3. Pure computation: Write fn definitions while separating effects where possible.
  4. Small examples: Use run and test to check intended behavior.
  5. Propositions: Declare invariants with theorem, Eq, and related tools.
  6. Proofs: Use constructor matching, lemmas, and equality rewrites.
  7. Boundaries: List external operations and runtime-dependent components.

21.3 Take the next step

The repository's examples/ directory contains larger versions of topics introduced here:

  • sort/: insertion sort for arbitrary Ord types, with proofs.
  • bst/: a binary search tree representing a set, with proofs.
  • compiler/: compiling arithmetic expressions to a stack machine, with a correctness proof.
  • effect-proofs/: effect handlers calling proved transitions.
  • certified-state/: connecting proved state transitions to runtime code.

Once natural-number arithmetic is familiar, explore the relationship between Prop, inductive, and Type. If effects interest you, investigate how resume ω interacts with state and ownership.

Finally, prioritize small, precise assumptions and conclusions over impressive theorem names. That leads toward software whose meaning can be read and mechanically checked in Tauto.