Code, Contracts & Types · Page 5 of 6
Function Contracts
Not every specification is a state machine. A module-level function whose return type
carries Requires or Ensures is a function contract.
Its predicates bind the function's parameters by name (and result
in Ensures), and a predicate may omit parameters it does not need. For every
argument tuple in the model's domains where every Requires and
parameter Where holds, the checker verifies that the body returns without error
and satisfies every Ensures and return-type Where.
Notice implies(p, q) in clamp: it expresses logical implication
(not p or q) cleanly in predicates.
Try it: Click Check to exhaustively verify both
clamp (343 input tuples) and integer_sqrt (50 inputs).
Then introduce an off-by-one bug in clamp — e.g., change return low
to return low - 1 — and watch the checker print the exact failing arguments!