The Curry-Howard correspondence connects logic and computation through data types: a data type acts as an assertion, while an instance proves that the assertion has been satisfied. In practical Java design, this turns invariants into compiler-visible boundaries rather than leaving them as assumptions. section 9.3.2
A proof-carrying type can guard any point in an application, not merely an interface or architectural layer. Code that accepts ValidCart instead of Cart demands evidence that validation and required construction steps have already succeeded. section 9.3.2 section 9.6
Guarding checkout with ValidCart
A cart endpoint can load and validate a cart, add items, and establish a boundary by constructing ValidCart. Subsequent operations—computing subtotals, checking free-shipping progress, and retrieving recommendations—accept only that stronger type. Each function therefore works from concrete knowledge instead of repeating assumptions about cart state. section 9.3.2
Applying the correspondence to legacy code means:
- Work backward from required invariants rather than beginning with object responsibilities or architectural layers. section 9.3.2
- Use constructors and dedicated data types to prevent invalid or partially validated states from spreading. section 9.6
