The Ultimate Conditional Syntax
Luyu Cheng, Lionel Parreaux
Abstract
Functional programming languages typically support expressive pattern-matching syntax allowing programmers to write concise and type-safe code, especially appropriate for manipulating algebraic data types. Many features have been proposed to enhance the expressiveness of stock pattern-matching syntax, such as pattern bindings, pattern alternatives (a.k.a. disjunction), pattern conjunction, view patterns, pattern guards, pattern synonyms, active patterns, ‘if-let’ patterns, multi-way if-expressions, etc. In this paper, we propose a new pattern-matching syntax that is both more expressive and (we argue) simpler and more readable than previous alternatives. Our syntax supports parallel and nested matches interleaved with computations and intermediate bindings. This is achieved through a form of nested multi-way if-expressions with a condition-splitting mechanism to factor common conditional prefixes as well as a binding technique we call conditional pattern flowing . We motivate this new syntax with many examples in the setting of MLscript, a new ML-family programming language. We describe a straightforward desugaring pass from our rich source syntax into a minimal core syntax that only supports flat patterns and has an intuitive small-step semantics. We then provide a translation from the core syntax into a normalized syntax without backtracking, which is more amenable to coverage checking and compilation, and formally prove that our translation is semantics-preserving. We view this work as a step towards rethinking pattern matching to make it more powerful and natural to use. Our syntax can easily be integrated, in part or in whole, into existing as well as future programming language designs.
Ask about this paper
Ask your agent about it.
Lune has read the top-tier papers around this one, so every answer names the papers it rests on.
Your agent calls
Lunesearch_papers
Free to start. No credit card required.
Terminal
Install the CLIlune papers get aae9f16a-5b26-4f53-8ac9-8e35ecf62c17Related papers
- Programming with Composable Recursive Patterns and TransformationsLuyu Cheng, Florent Ferrari, Michael D. Adams, Lionel ParreauxOOPSLA 2026
- Persimmon: Nested Family Polymorphism with Extensible Variant TypesAnastasiya Kravchuk-Kirilyuk, Gary Feng, Jonas Iskander, Yizhou Zhang et al.OOPSLA 2024 · 4 citations
- Validating Soundness and Completeness in Pattern-Match Coverage AnalyzersCyril Moser, Thodoris Sotiropoulos, Chengyu Zhang, Zhendong SuOOPSLA 2025 · 1 citation
- Type-level programming with match typesOlivier Blanvillain, Jonathan Immanuel Brachthäuser, Maxime Kjaer, Martin OderskyPOPL 2022 · 10 citations
- Disentanglement in nested-parallel programsSam Westrick, Rohan Yadav, Matthew Fluet, Umut A. AcarPOPL 2020 · 19 citations
