Hong Kong University of Science and Technology
Improving the Expressiveness and Efficiency of Pattern Matching
Abstract
dc:description<p>Pattern matching is now widely adopted in typed programming languages, but the match expression has changed little since its introduction: one scrutinee, a fixed list of patterns, no interleaving of pattern tests with Boolean conditions or intermediate computations, and no way to name, compose, or reuse a pattern. This thesis extends pattern matching in both directions — at use sites, where programs write match expressions, and at definition sites, where patterns themselves are defined.</p> <p>At use sites, we present the Ultimate Conditional Syntax (UCS). A pattern test becomes an ordinary condition whose pattern variables scope over its logical continuation, so matching, Boolean tests, computations, and bindings interleave in one construct. The syntax desugars into a core calculus. A semantics-preserving normalization translates core terms into a non-backtracking subset.</p> <p>At definition sites, we present Composable Recursive Patterns and Transformations (CRPT), which makes patterns named, recursive, parameterized, composable with Boolean connectives, and able to transform matched components. Each pattern records a domain, a success codomain, and a residual failure codomain, and elaborates soundly into MLstruct, a Boolean algebra structural type system with principal type inference. We give an optimized semantics that matches whole pattern sets simultaneously, prove it equivalent to the declarative semantics and terminating, with runtime linear in the input for any fixed compiled pattern set.</p> <p>Benchmarks against validation libraries confirm the predicted non-backtracking behavior.</p> <p>Both extensions are implemented in MLscript, our research group’s programming language. We demonstrate them through a case study — a parser for a Caml Light dialect — and two further applications: evaluation contexts modeled as higher-order patterns, and a lexer whose token classes are string patterns. The use-site and definition-site extensions compose: programs can interleave conditions with recursive, composable patterns that introduce refinement types, and the compiled matchers execute in linear time without backtracking.</p>
Author and committee
dc:creator, dc:contributor.*- Author dc:creator
-
- Cheng, Luyu
- Contributors dc:contributor
-
- Parreaux, Lionel
Rights
- Language dc:language
- English
Identifiers
dc:identifier.*- Repository record dc:identifier
- http://repository.hkust.edu.hk/ir/Record/1783.1-174782