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 条
  • [41] Syntax, Semantics, and Computer Programs
    William J. Rapaport
    Philosophy & Technology, 2020, 33 (2) : 309 - 321
  • [42] Three Mathematical Foundations for Syntax
    Stabler, Edward P.
    ANNUAL REVIEW OF LINGUISTICS, VOL 5, 2019, 5 : 243 - 260
  • [43] The Syntax and Semantics of Nonfinite Forms
    Lowe, John J.
    ANNUAL REVIEW OF LINGUISTICS, VOL 5, 2019, 5 : 309 - 328
  • [44] The syntax of intonation units in Sasak
    Wouk, Fay
    STUDIES IN LANGUAGE, 2008, 32 (01): : 137 - 162
  • [45] Phonology and syntax:: a shifting relationship
    Bermúdez-Otero, R
    Honeybone, P
    LINGUA, 2006, 116 (05) : 543 - 561
  • [46] The Syntax and Semantics of Verbs of Searching
    Wang, Shan
    Chen, Shuchi
    EMERGING TECHNOLOGIES FOR EDUCATION, SETE 2021, 2021, 13089 : 122 - 141
  • [47] The syntax of focus in Caucasian Urum
    Schroeter, Stefanie
    LINGUA, 2019, 229
  • [48] The emergence of complexity in prosody and syntax
    Sandler, Wendy
    Meir, Irit
    Dachkovsky, Svetlana
    Padden, Carol
    Aronoff, Mark
    LINGUA, 2011, 121 (13) : 2014 - 2033
  • [49] The syntax-morphology relation
    Holmberg, Anders
    Roberts, Ian
    LINGUA, 2013, 130 : 111 - 131
  • [50] INITIAL EXPLICATION OF THE CONCEPT OF SYNTAX
    Sopauskas, Laisvunas
    PROBLEMOS, 2010, 77 : 80 - 91