一句话:提出更简单正交的显式空值 blame 演算,用标准方式证明 blame 定理并支持开放项互嵌。
渐进类型刻画精度不同的语言如何交互,cast 负责转换类型并在值不匹配时分配 blame,blame 定理保证责任落在精度较低一侧。针对 Java 等允许任意类型取 null、而 Scala/Kotlin 等显式标记可空类型的场景,Nieto 等人 2020 年提出相应演算,但它需要三种函数类型构造子、非标准 blame 定理证明,且只能在项封闭时嵌入遗留语言与新型语言。本文给出更简单、更正交的演算:仅一个函数类型构造子和一个可空类型构造子,采用完全标准的 blame 定理证明,并允许开放项双向嵌入。所有结果已在 Coq 中机械化。
Abstract Gradual typing provides a model for when a legacy language with less precise types interacts with a newer language with more precise types. Casts mediate between types of different precision, allocating blame when a value fails to conform to a type. The blame theorem asserts that blame always falls on the less-precisely typed side of a cast. One instance of interest is when a legacy language (such as Java) permits null values at every type, while a newer language (such as Scala or Kotlin) explicitly indicates which types permit null values. Nieto et al. in 2020 introduced a gradually typed calculus for just this purpose. The calculus requires three distinct constructors for function types and a non-standard proof of the blame theorem; it can embed terms from the legacy language into the newer language (or vice versa) only when they are closed. Here, we define a simpler calculus that is more orthogonal, with one constructor for function types and one for possibly nullable types, and with an entirely standard proof of the blame theorem; it can embed terms from the legacy language into the newer language (and vice versa) even if they are open. All results in the paper have been mechanized in Coq.