Expand description
Free theorems: what a generic proposition promises before any proof runs.
A proof of reverse<T> : [T] -> [T] cannot look at a T. It was given no
way to — no comparison, no field, no method, nothing but the shape around
it — so whatever it does, it does the same way whatever T turns out to be.
That is a theorem about every proof of the proposition, and it follows
from the signature alone (Reynolds’s abstraction theorem; Wadler’s
“Theorems for free!”). Two consequences can be checked by running a proof:
- Conservation. Every
Tin the result was one of theTs in the arguments. A proof cannot make one up, because it does not know what one looks like. - Naturality. Relabelling the
Ts commutes with the proof: for anyg,f(map g xs) = map g (f xs). What the proof does is a function of shape, not of content.
Neither needs anyone to say what the right answer is, and neither needs a
vector file. The harness fills each T position with a distinct token,
runs the proof, and reads off which token landed where. That checks
conservation outright, and it predicts what the proof must say at any
other type — so it runs again with the tokens relabelled: once as distinct
strings, once all onto a single boolean, and once onto two integers, and
checks that each answer is the first one relabelled the same way. A proof
that sorts when handed integers, or compares two elements and branches, or
only works at the one type its author had in mind, is caught by one of
those.
One type is enough to test a parametric proof at, which is the practical face of the theorem: there is no second type at which it could behave differently, so there is no second type to try.
§What this does not cover
A bounded parameter — T: Identified — can be looked at, through the
bound, so a proof may lawfully treat one T differently from another, and
the theorem weakens to naturality over relabellings that respect the bound.
That is a later addition; here a bounded proposition is reported as not
checkable rather than held to a law it need not obey. The same goes for a
T under an untagged union, where a value does not say whether it is the
T, and for parameters whose types cannot be filled from nothing, such as
functions and interfaces.
Structs§
- Theorems
- How a proposition’s free theorem fared across every proof and trial.
- Trial
- One shape the proposition was tried at.
Enums§
- Law
- One of the laws a parametric proof is held to.
- Parametric
Error - Why a proposition’s free theorem could not be checked.
- Verdict
- What became of one proof on one trial.