一句话:提出将依赖(余)模式匹配定义加工为核心语言 case tree 的算法,证明其保持首匹配语义并改进 Agda 实现。
在依赖类型语言中,程序与证明会被类型检查器加工成底层核心语言,但用户定义的依赖余模式匹配如何正确翻译为 case tree 长期缺乏形式化说明。本文针对这一“第一步”,提出将依赖余模式匹配定义加工为含归纳数据类型、余归纳记录类型、同一性类型和良类型 case tree 常量的核心语言的算法。作者证明该加工保持用户子句的首匹配语义,并用该理论重新实现 Agda 检查模式匹配左侧的算法。新实现更通用、更简单,并修复旧版若干错误与可用性问题,向实用依赖类型语言的形式验证实现迈进一步。
Abstract In a dependently typed language, we can guarantee correctness of our programmes 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 programmes 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 data types, 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.