Many programming languages in the OO tradition now support pattern matching in some form. Historical examples include Scala and Ceylon, with the more recent additions of Java, Kotlin, TypeScript, and Flow. But pattern matching on generic class hierarchies currently results in puzzling type errors in most of these languages. Yet this combination of features occurs naturally in many scenarios, such as when manipulating typed ASTs. To support it properly, compilers needs to implement a form of subtyping reconstruction: the ability to reconstruct subtyping information uncovered at runtime during pattern matching. We introduce cDOT, a new calculus in the family of Dependent Object Types (DOT) intended to serve as a formal foundation for subtyping reconstruction. Being descended from pDOT, itself a formal foundation for Scala, cDOT can be used to encode advanced object-oriented features such as generic inheritance, type constructor variance, F-bounded polymorphism, and first-class recursive modules. We demonstrate that subtyping reconstruction subsumes GADTs by encoding $\lambda_{2,G\mu}$, a classical constraint-based GADT calculus, into cDOT.
翻译:OO 传统中许多编程语言现在以某种形式支持模式匹配。历史实例包括 Scala 和 Ceylon, 以及最近加入的 Java、 Kotlin、 TyScript 和 Flow 。 但是, 普通类等级结构的匹配模式目前导致大多数这类语言的分类错误。 但是, 在许多情景中, 这种特征的结合自然地发生, 比如在调控打字 AST 时。 为了适当支持它, 编译者需要实施一种亚型重建的形式: 重建运行时在模式匹配过程中发现的亚型信息的能力 。 我们引入了 CDOT, 独立对象类型(DOT) 家族中的新微积分器(DOT), 意在作为亚型重建的正式基础 。 从PDOT( 本身是 Scala 的正式基础), CDOT 可以用来编码先进的面向对象的特征, 如通用遗产、 类型构建者差异、 受限制的多元形态和一等等。 我们证明, 亚型的重建子化的重建以GDGA- gal- galendulda2, GADDDDG=G- caldusimmus