## 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 language | English |
---|---|

Pages (from-to) | 113-132 |

Number of pages | 20 |

Journal | Computer Software |

Volume | 24 |

Issue number | 2 |

Publication status | Published - 2007 Jun 11 |

Externally published | Yes |

## ASJC Scopus subject areas

- Software