Gradual Typing Theory
Gradual typing allows precise and unknown types to coexist. Consistency determines where casts may be inserted, and blame records which boundary failed.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 3
- Reading time
- 1 min
In this article3 chapters
Consistency is a compatibility check
In a simple calculus, an unknown type is consistent with every value type. Consequently
\[ \mathrm{Int}\sim ?,\qquad ?\sim\mathrm{Bool},\qquad \mathrm{Int}\not\sim\mathrm{Bool}. \]
Consistency is symmetric and need not be transitive. It cannot be used as if it were ordinary type equality. A cast calculus elaborates a consistent use into a run-time check or a wrapper. The unknown type stands for incomplete static information, while the value still follows the operational rules of the language.
A runtime cast explains how a boundary check can appear during evaluation. Progress and preservation provide the underlying proof pattern for distinguishing an authorized dynamic check from a stuck computation.
Higher-order casts need two directions of blame
If a dynamically supplied value is used as a function from integers to Booleans, an adapter can check that calls supply integers and that returned values are Booleans. Incorrect arguments and incorrect results originate on different sides of the boundary. A blame calculus uses the polarity of the cast to assign the failure. Without checking the result when it is produced, merely seeing a function value would establish too little about the behavior of future calls.
Precision relates programs across annotations
A dynamic gradual guarantee gives a semantic relation between programs when annotations are made less precise. Its precise wording depends on the calculus and how it orders errors and values. A static guarantee concerns typeability instead. Neither follows from accepting unknown types alone. Proofs compare elaborated terms and how their casts reduce. These questions connect to language semantics, richer constraints in refinement types, and the operational effect of handlers in effect systems.[1][2]