[论文解读] A Quantitative Understanding of Pattern Matching
本文提出了两种资源感知的类型系统 $τ\mathscr{U}$ 和 $τ\mathscr{E}$,用于带有对模式匹配的 $λ$-演算。通过使用带有装饰型上下文的非幂等交集类型,$τ\mathscr{E}$ 对头归约序列的长度和归约范型的大小提供了精确界限,通过分别为 β、替换和匹配步骤设置独立计数器,区分了时间(归约步骤)与空间(项大小)。
This paper shows that the recent approach to quantitative typing systems for programming languages can be extended to pattern matching features. Indeed, we define two resource aware type systems, named U and E, for a lambda-calculus equipped with pairs for both patterns and terms. Our typing systems borrow some basic ideas from [BKRDR15], which characterises (head) normalisation in a qualitative way, in the sense that typability and normalisation coincide. But in contrast to [BKRDR15], our (static) systems also provides quantitative information about the dynamics of the calculus. Indeed, system U provides upper bounds for the length of normalisation sequences plus the size of their corresponding normal forms, while system E, which can be seen as a refinement of system U, produces exact bounds for each of them. This is achieved by means of a non-idempotent intersection type system equipped with different technical tools. First of all, we use product types to type pairs, instead of the disjoint unions in [BKRDR15], thus avoiding an overlap between "being a pair" and "being duplicable", resulting in an essential tool to reason about quantitativity. Secondly, typing sequents in system E are decorated with tuples of integers, which provide quantitative information about normalisation sequences, notably time (c.f. length) and space (c.f. size). Another key tool of system E is that the type system distinguishes between consuming (contributing to time) and persistent (contributing to space) constructors. Moreover, the time resource information is remarkably refined, because it discriminates between different kinds of reduction steps performed during evaluation, so that beta reduction, substitution and matching steps are counted separately.
研究动机与目标
- 通过原生建模模式匹配而非作为语法糖,弥合 $λ$-演算与现代函数式语言之间的概念鸿沟。
- 将定量类型系统扩展至模式匹配,不仅提供终止保证,还提供计算资源的精确界限。
- 通过在归约序列中区分时间(归约步骤)与空间(项大小),细化资源会计。
- 开发一种能够分别追踪不同类型的归约步骤(β、替换和匹配)的类型系统,以实现细粒度分析。
- 通过使用装饰型上下文编码精确界限,建立类型推导与求值动态之间的正式联系。
提出的方法
- 系统 $τ\mathscr{U}$ 使用非幂等交集类型与乘积类型来对对进行类型标注,避免了‘是配对’与‘可复制’之间的重叠。
- $τ\mathscr{E}$ 中的类型推导上下文通过元组 $(b, e, m, f)$ 进行装饰,分别表示时间(β 步骤)、空间(替换步骤)、匹配步骤和最终大小。
- 该系统区分了消耗构造器(影响时间)与持久构造器(影响空间),从而实现精确的资源追踪。
- 归约步骤被分别计数:β 归约、替换和模式匹配各自通过装饰中的独立分量进行追踪。
- 该类型系统采用一种新型的类型推导形式,其中推导的大小对应于归约序列的长度,其结构编码了归约范型的大小。
- 一项关键技术革新是使用多集合类型系统,其中类型带有随归约规则演化的计数器,确保精确界限。
实验结果
研究问题
- RQ1能否将定量类型系统扩展至原生处理 $λ$-演算中的模式匹配?
- RQ2此类系统能否对头归约序列的长度和归约后范型的大小都提供精确界限?
- RQ3能否在类型系统中区分并分别计数不同类型的归约步骤(β、替换和匹配)?
- RQ4能否在类型系统中形式化消耗构造器与持久构造器之间的区别,以细化时间和空间界限?
- RQ5能否利用类型推导的大小来精确预测步骤数量和最终项的大小?
主要发现
- 系统 $τ\mathscr{U}$ 对头归约序列的长度及其归约范型的大小均提供了上界。
- 系统 $τ\mathscr{E}$ 对归约序列的长度和归约范型的大小均提供了精确界限,无过度近似。
- $τ\mathscr{E}$ 系统区分了三种归约步骤:β 归约、替换和模式匹配,每种均对时间计数器有贡献。
- $τ\mathscr{E}$ 中的时间计数器被细化,以独立追踪每类步骤的贡献,从而实现精确的动态分析。
- $τ\mathscr{E}$ 中类型推导的大小恰好等于头归约序列的长度,最终的装饰结构反映了归约范型的大小。
- 使用乘积类型而非不相交并集避免了‘是配对’与‘可复制’之间的概念重叠,从而实现了对定量性质更清晰的推理。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。