一句话:提出中间语言 λBDTI,将静态推断未定的类型变量推迟到运行时实例化,避免翻译发散并证明渐进保证。
Garcia 与 Cimini 为隐式渐进类型语言 ITGL 给出可靠且完备的类型推断算法,但其翻译中静态未定的类型变量可有多种具体实例化,导致不同翻译行为不同:有求值为值,有触发 blame。本文提出并形式化新的 blame calculus λBDTI 作为 ITGL 的中间语言。其核心是允许项保留未实例化类型变量,并在语义中引入动态类型推断(DTI),随归约在运行时实例化这些变量,从而避免上述发散。该语义对显式 blame calculus 中完全实例化项的语义可靠且完备:DTI 求值成功当且仅当存在成功求值的完全实例化版本。最后证明 ITGL 的渐进保证。
Garcia and Cimini study a type inference problem for the ITGL, an implicitly and gradually typed language with let-polymorphism, and develop a sound and complete inference algorithm for it. Soundness and completeness mean that, if the algorithm succeeds, the input term can be translated to a well-typed term of an explicitly typed blame calculus by cast insertion and vice versa. However, in general, there are many possible translations depending on how type variables that were left undecided by static type inference are instantiated with concrete static types. Worse, the translated terms may behave differently—some evaluate to values but others raise blame. In this paper, we propose and formalize a new blame calculus λ B DTI that avoids such divergence as an intermediate language for the ITGL. A main idea is to allow a term to contain type variables (that have not been instantiated during static type inference) and defer instantiation of these type variables to run time. We introduce dynamic type inference (DTI) into the semantics of λ B DTI so that type variables are instantiated along reduction. The DTI-based semantics not only avoids the divergence described above but also is sound and complete with respect to the semantics of fully instantiated terms in the following sense: if the evaluation of a term succeeds (i.e., terminates with a value) in the DTI-based semantics, then there is a fully instantiated version of the term that also succeeds in the explicitly typed blame calculus and vice versa. Finally, we prove the gradual guarantee, which is an important correctness criterion of a gradually typed language, for the ITGL.
@article{paperbot627,
title = {Dynamic type inference for gradual Hindley–Milner typing},
author = {Yusuke Miyazaki and Taro Sekiyama and Atsushi Igarashi},
journal = {Proceedings of the ACM on Programming Languages},
volume = {3},
number = {POPL},
year = {2019},
doi = {10.1145/3290331}
}