Gradual Types and Runtime Cast Boundaries

Follow a value across a typed boundary and see why checking a function requires obligations on later calls and returns.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Dynamic values can carry evidence for later checks
  2. A function contract can require a wrapper

Dynamic values can carry evidence for later checks

A gradual language can let an unannotated value flow into a context requiring an integer. A runtime cast then checks whether the value satisfies that expectation. Success yields a value valid for the receiving context. Failure is associated with a boundary whose contract could not be met. The exact consistency relation and cast insertion rules belong to the language’s model.

A function contract can require a wrapper

Suppose a dynamic function is used as a function from integers to Booleans. Merely observing that it is callable cannot guarantee its future results. A cast can wrap it so each call respects the argument contract and each returned value is checked for Boolean type. Higher-order checking follows both sides of the variance rules. Gradual typing theory formalizes how changing annotations affects static acceptance and dynamic behavior.[1][2]

References

  1. Jeremy G. Siek and Walid Taha, Gradual Typing for Functional Languages ↩
  2. Shriram Krishnamurthi, Programming Languages: Application and Interpretation ↩