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 条
  • [1] Experimental syntax and syntax experiment
    Fedorova, O. V.
    VOPROSY YAZYKOZNANIYA, 2013, (01): : 3 - 21
  • [2] Wave to Syntax: Probing spoken language models for syntax
    Shen, Gaofei
    Alishahi, Afra
    Bisazza, Arianna
    Chrupala, Grzegorz
    INTERSPEECH 2023, 2023, : 1259 - 1263
  • [3] Pictorial syntax
    Lande, Kevin J.
    MIND & LANGUAGE, 2024, 39 (04) : 518 - 539
  • [4] Lists with and without Syntax: A New Approach to Measuring the Neural Processing of Syntax
    Law, Ryan
    Pylkkanen, Liina
    JOURNAL OF NEUROSCIENCE, 2021, 41 (10) : 2186 - 2196
  • [6] On the syntax of complex utterances
    Gutierrez Ordonez, Salvador
    CIRCULO DE LINGUISTICA APLICADA A LA COMUNICACION, 2018, (75): : 3 - 18
  • [7] SYNTAX AS AN OBJECT OF PARODY
    Norman, Boris Ju
    PHILOLOGICAL CLASS, 2021, 26 (02): : 40 - 51
  • [8] The Cortical Organization of Syntax
    Matchin, William
    Hickok, Gregory
    CEREBRAL CORTEX, 2020, 30 (03) : 1481 - 1498
  • [9] Computational Learning of Syntax
    Clark, Alexander
    ANNUAL REVIEW OF LINGUISTICS, VOL 3, 2017, 3 : 107 - 123
  • [10] Persistent Topology of Syntax
    Port, Alexander
    Gheorghita, Iulia
    Guth, Daniel
    Clark, John M.
    Liang, Crystal
    Dasu, Shival
    Marcolli, Matilde
    MATHEMATICS IN COMPUTER SCIENCE, 2018, 12 (01) : 33 - 50