[Paper Review] A Quantitative Understanding of Pattern Matching
This paper introduces two resource-aware type systems, $τ\mathscr{U}$ and $τ\mathscr{E}$, for a $λ$-calculus with pattern matching over pairs. By using non-idempotent intersection types with decorated typing sequents, $τ\mathscr{E}$ provides exact bounds on both the length of head normalisation sequences and the size of normal forms, distinguishing between time (reduction steps) and space (term size) via separate counters for beta, substitution, and matching steps.
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.
Motivation & Objective
- To close the conceptual gap between $λ$-calculi and modern functional languages by modeling pattern matching natively, rather than as a syntactic sugar.
- To extend quantitative type systems to pattern matching, providing not just termination guarantees but precise bounds on computational resources.
- To refine resource accounting by distinguishing between time (reduction steps) and space (term size) in normalisation sequences.
- To develop a type system that tracks different kinds of reduction steps—beta, substitution, and matching—separately for fine-grained analysis.
- To establish a formal link between typing derivations and dynamics of evaluation, using decorated sequents to encode exact bounds.
Proposed method
- The system $τ\mathscr{U}$ uses non-idempotent intersection types with product types to type pairs, avoiding overlap between 'being a pair' and 'being duplicable'.
- Typing sequents in $τ\mathscr{E}$ are decorated with tuples $(b, e, m, f)$ representing time (beta steps), space (substitution steps), matching steps, and final size.
- The system distinguishes consuming constructors (affecting time) from persistent ones (affecting space), enabling precise resource tracking.
- Reduction steps are counted separately: beta reduction, substitution, and pattern matching are each tracked via distinct components of the decoration.
- The type system uses a novel form of typing derivation where the size of the derivation corresponds to the length of the normalisation sequence, and the structure encodes the size of the normal form.
- A key technical innovation is the use of a multi-set type system where types are decorated with counters that evolve according to reduction rules, ensuring exact bounds.
Experimental results
Research questions
- RQ1Can quantitative type systems be extended to natively handle pattern matching in a $λ$-calculus?
- RQ2Can such systems provide exact bounds on both the length of head normalisation sequences and the size of the resulting normal forms?
- RQ3Can different kinds of reduction steps—beta, substitution, and matching—be distinguished and counted separately in a type system?
- RQ4Can the distinction between consuming and persistent constructors be formalized in a type system to refine time and space bounds?
- RQ5Can the size of a typing derivation be used to precisely predict both the number of steps and the size of the final term?
Key findings
- System $τ\mathscr{U}$ provides upper bounds on both the length of head normalisation sequences and the size of their normal forms.
- System $τ\mathscr{E}$ provides exact bounds for both the length of normalisation sequences and the size of normal forms, with no over-approximation.
- The system $τ\mathscr{E}$ distinguishes between three kinds of reduction steps: beta reduction, substitution, and pattern matching, each contributing to the time counter.
- The time counter in $τ\mathscr{E}$ is refined to track the contribution of each step type independently, enabling precise dynamic analysis.
- The size of the typing derivation in $τ\mathscr{E}$ exactly matches the length of the head normalisation sequence, and the final decoration reflects the size of the normal form.
- The use of product types instead of disjoint unions avoids the conceptual overlap between 'being a pair' and 'being duplicable', enabling cleaner reasoning about quantitativity.
Better researchstarts right now
From reading papers to final review, dramatically reduce your research time.
No credit card · Free plan available
This review was created by AI and reviewed by human editors.