Research output: Contribution to book/anthology/report/proceeding › Article in proceedings › Research › peer-review
Final published version
We propose restrictable variants as a simple and practical alternative to extensible variants. Restrictable variants combine nominal and structural typing: a restrictable variant is an algebraic data type indexed by a type-level set formula that captures its set of active labels. We introduce new pattern-matching constructs that allows programmers to write functions that only match on a subset of variants, i.e., pattern-matches may be non-exhaustive. We then present a type system for restrictable variants which ensures that such non-exhaustive matches cannot get stuck at runtime. An essential feature of restrictable variants is that the type system can capture structure-preserving transformations: specifically the introduction and elimination of variants. This property is important for writing reusable functions, yet many row-based extensible variant systems lack it. In this paper, we present a calculus with restrictable variants, two partial pattern-matching constructs, and a type system that ensures progress and preservation. The type system extends Hindley-Milner with restrictable variants and supports type inference with an extension of Algorithm W with Boolean unification. We implement restrictable variants as an extension of the Flix programming language and conduct a few case studies to illustrate their practical usefulness.
Original language | English |
---|---|
Title of host publication | 37th European Conference on Object-Oriented Programming, ECOOP 2023 |
Editors | Karim Ali, Guido Salvaneschi |
Publisher | Schloss Dagstuhl--Leibniz-Zentrum für Informatik |
Publication year | Jul 2023 |
Pages | 17:1-17:27 |
Article number | 17 |
ISBN (electronic) | 9783959772815 |
DOIs | |
Publication status | Published - Jul 2023 |
Event | 37th European Conference on Object-Oriented Programming, ECOOP 2023 - Seattle, United States Duration: 17 Jul 2023 → 21 Jul 2023 |
Conference | 37th European Conference on Object-Oriented Programming, ECOOP 2023 |
---|---|
Land | United States |
By | Seattle |
Periode | 17/07/2023 → 21/07/2023 |
Series | Leibniz International Proceedings in Informatics, LIPIcs |
---|---|
Volume | 263 |
ISSN | 1868-8969 |
Publisher Copyright:
© Magnus Madsen, Jonathan Lindegaard Starup, and Matthew Lutze;
See relations at Aarhus University Citationformats
ID: 341335169