A fresh look at pattern matching compilation

Atsushi Ohori, Satoshi Osaka

Research output: Contribution to journalArticle

Abstract

This paper presents a denotational semantics for patten matching compilation, and develops a simple algorithm to compile pattern matching into efficient code. We interpret a given set of patterns as a disjoint set of subsets of values that partition the domain of a given type, and define a semantics of a pattern matching construct as an operation to determine the subset to which a given value belongs. By developing tree representations for subsets of values, this semantics yields a simple tree-expansion algorithm to compile a pattern matching construct into a sequence of primitive tests. The resulting algorithm is shown to be correct with respect to the denotational semantics The algorithm produces efficient code performing each test only once, and detects redundancy and non-exhaustiveness of a given set of patterns without introducing any additional mechanism. The presented method has been implemented for SML#, an extension of the Standard ML language being developed at Research Institute of Electrical Communication, Tohoku University.

Original languageEnglish
Pages (from-to)113-132
Number of pages20
JournalComputer Software
Volume24
Issue number2
Publication statusPublished - 2007 Jun 11

ASJC Scopus subject areas

  • Software

Fingerprint Dive into the research topics of 'A fresh look at pattern matching compilation'. Together they form a unique fingerprint.

  • Cite this