一句话:将渐进保证重构为 Graduality,并用嵌入-投影对与逻辑关系证明它,类比参数性。
渐进类型语言允许静态与动态类型代码交互,其核心推理原则是渐进保证:给程序组件更精确的类型只会增加运行时类型检查,不改变其他行为。本文给出该保证的语义重构,称为 Graduality,类比参数性之于多态。作者提出局部到全局、语法到语义的观测近似原则,并开发新的逻辑关系来证明 Graduality。关键观察是,当两个类型中一个“更动态”(更不精确)时,它们之间的 cast 必然构成嵌入-投影对;从 ep-pair 性质可干净证明 cast 的 Graduality 情形。为构造 ep pairs,作者分析类型动态性关系(类型精度/朴素子类型),将其规则解释为 ep pairs 的复合构造,类似子类型的 coercion 解释。该工作为渐进类型提供了统一的语义推理框架。
Gradually typed languages allow statically typed and dynamically typed code to interact while maintaining benefits of both styles. The key to reasoning about these mixed programs is Siek-Vitousek-Cimini-Boyland’s (dynamic) gradual guarantee, which says that giving components of a program more precise types only adds runtime type checking, and does not otherwise change behavior. In this paper, we give a semantic reformulation of the gradual guarantee called graduality . We change the name to promote the analogy that graduality is to gradual typing what parametricity is to polymorphism. Each gives a local-to-global, syntactic-to-semantic reasoning principle that is formulated in terms of a kind of observational approximation. Utilizing the analogy, we develop a novel logical relation for proving graduality. We show that embedding-projection pairs (ep pairs) are to graduality what relations are to parametricity. We argue that casts between two types where one is “more dynamic” (less precise) than the other necessarily form an ep pair, and we use this to cleanly prove the graduality cases for casts from the ep-pair property. To construct ep pairs, we give an analysis of the type dynamism relation—also known as type precision or naïve subtyping—that interprets the rules for type dynamism as compositional constructions on ep pairs, analogous to the coercion interpretation of subtyping.