一句话:提出依赖(共)模式匹配到良类型 case tree 核心语言的精化算法,并证明其保持用户子句的首匹配语义。
依赖类型语言中,类型检查器需将程序与证明精化到低层核心语言,但核心语言难以理解,尤其依赖共模式匹配定义的精化步骤此前被忽视。本文提出算法,把依赖(共)模式匹配定义精化为含归纳数据类型、余归纳记录类型、identity type 与良类型 case tree 常量的核心语言,并证明该精化保持用户子句的首匹配语义。作者据此重新实现 Agda 检查模式匹配左侧的算法;新实现更通用、更简单,修复旧版缺陷与可用性问题,是迈向实用依赖类型语言形式验证实现的一步。
In a dependently typed language, we can guarantee correctness of our programs by providing formal proofs. To check them, the typechecker elaborates these programs and proofs into a low level core language. However, this core language is by nature hard to understand by mere humans, so how can we know we proved the right thing? This question occurs in particular for dependent copattern matching, a powerful language construct for writing programs and proofs by dependent case analysis and mixed induction/coinduction. A definition by copattern matching consists of a list of clauses that are elaborated to a case tree , which can be further translated to primitive eliminators . In previous work this second step has received a lot of attention, but the first step has been mostly ignored so far. We present an algorithm elaborating definitions by dependent copattern matching to a core language with inductive datatypes, coinductive record types, an identity type, and constants defined by well-typed case trees. To ensure correctness, we prove that elaboration preserves the first-match semantics of the user clauses. Based on this theoretical work, we reimplement the algorithm used by Agda to check left-hand sides of definitions by pattern matching. The new implementation is at the same time more general and less complex, and fixes a number of bugs and usability issues with the old version. Thus we take another step towards the formally verified implementation of a practical dependently typed language.