Restrictable Variants: A Simple and Practical Alternative to Extensible Variants

Magnus Madsen*, Jonathan Lindegaard Starup*, Matthew Lutze*

*Corresponding author af dette arbejde

Publikation: Bidrag til bog/antologi/rapport/proceedingKonferencebidrag i proceedingsForskningpeer review

Abstract

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.

OriginalsprogEngelsk
Titel37th European Conference on Object-Oriented Programming, ECOOP 2023
RedaktørerKarim Ali, Guido Salvaneschi
ForlagSchloss Dagstuhl--Leibniz-Zentrum für Informatik
Publikationsdatojul. 2023
Sider17:1-17:27
Artikelnummer17
ISBN (Elektronisk)9783959772815
DOI
StatusUdgivet - jul. 2023
Begivenhed37th European Conference on Object-Oriented Programming, ECOOP 2023 - Seattle, USA
Varighed: 17 jul. 202321 jul. 2023

Konference

Konference37th European Conference on Object-Oriented Programming, ECOOP 2023
Land/OmrådeUSA
BySeattle
Periode17/07/202321/07/2023
NavnLeibniz International Proceedings in Informatics, LIPIcs
Vol/bind263
ISSN1868-8969

Fingeraftryk

Dyk ned i forskningsemnerne om 'Restrictable Variants: A Simple and Practical Alternative to Extensible Variants'. Sammen danner de et unikt fingeraftryk.

Citationsformater