The Ultimate Conditional Syntax

被引:0
作者
Cheng, Luyu [1 ]
Parreaux, Lionel [1 ]
机构
[1] HKUST, Hong Kong, Peoples R China
来源
PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL | 2024年 / 8卷 / OOPSLA期
关键词
pattern matching; syntax; programming language design; POLYMORPHISM;
D O I
10.1145/3689746
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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.
引用
收藏
页数:30
相关论文
共 50 条
  • [31] Three Mathematical Foundations for Syntax
    Stabler, Edward P.
    ANNUAL REVIEW OF LINGUISTICS, VOL 5, 2019, 5 : 243 - 260
  • [32] Unified syntax in the bilingual mind
    Declerck, Mathieu
    Wen, Yun
    Snell, Joshua
    Meade, Gabriela
    Grainger, Jonathan
    PSYCHONOMIC BULLETIN & REVIEW, 2020, 27 (01) : 149 - 154
  • [33] The Syntax and Semantics of Nonfinite Forms
    Lowe, John J.
    ANNUAL REVIEW OF LINGUISTICS, VOL 5, 2019, 5 : 309 - 328
  • [34] Syntax, Semantics, and Computer Programs
    William J. Rapaport
    Philosophy & Technology, 2020, 33 (2) : 309 - 321
  • [35] The syntax of intonation units in Sasak
    Wouk, Fay
    STUDIES IN LANGUAGE, 2008, 32 (01): : 137 - 162
  • [36] decolonizing syntax: an indigenous dissertation
    Stewart, Patrick
    JOURNAL OF UNSCHOOLING AND ALTERNATIVE LEARNING, 2019, 13 (25) : 1 - 14
  • [37] Syntax, Truth, and the Fate of Sentences
    Collins, John
    PHILOSOPHICAL QUARTERLY, 2023, 74 (01) : 125 - 144
  • [38] Movement operations after syntax
    Embick, D
    Noyer, R
    LINGUISTIC INQUIRY, 2001, 32 (04) : 555 - 595
  • [39] The role of syntax in hashtag popularity
    Wan, Ming Feng
    LINGUISTICS VANGUARD, 2024, : 693 - 698
  • [40] Systematicity and natural language syntax
    Pullum, Geoffrey K.
    Scholz, Barbara C.
    CROATIAN JOURNAL OF PHILOSOPHY, 2007, 7 (21) : 375 - 402