A term pattern-match compiler inspired by finite automata theory

  • Mikael Pettersson
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 641)


This paper presents a new algorithm for compiling term patternmatching for functional languages. Earlier algorithms may produce duplicated code, and redundant or sub-optimal discrimination tests for certain combinations of patterns, in particular when a pattern column contains a mixture of constructors and variables. This algorithm, which was inspired by finite automata theory, addresses these problems and solves them to some extent. It does so by viewing patterns as regular expressions and optimizing the finite automaton that is built to recognize them. It also makes checking patterns for exhaustiveness and irredundancy cheap operations.


  1. [AGT89]
    A. V. Aho, M. Ganapathi, S. W. K. Tjiang, Code Generation Using Tree Matching and Dynamic Programming (ACM TOPLAS, Vol. 11(4), October 1989).Google Scholar
  2. [AJ89]
    Andrew W. Appel and Trevor Jim, Continuation-Passing, Closure-Passing Style (Proceedings 1989 ACM Symposium on Principles of Programming Languages).Google Scholar
  3. [Appel90]
    Andrew W. Appel, A Runtime System (Lisp and Symbolic Computation, Vol. 3, 343–380, 1990. Also in the “New Jersey” SML distribution.)Google Scholar
  4. [Augustsson85]
    Lennart Augustsson, Compiling Pattern-Matching (Proceedings 1985 Conference on Functional Programming Languages and Computer Architecture, Springer LNCS-201).Google Scholar
  5. [Bernstein85]
    Robert L. Bernstein, Producing Good Code for the Case Statement (Software — Practice and Experience, Vol. 15(10), October 1985).Google Scholar
  6. [Cardelli84]
    Luca Cardelli, Compiling a Functional Language (Proceedings 1984 ACM Conference on Lisp and Functional Programming).Google Scholar
  7. [HO82]
    Cristoph M. Hoffman and Michael J. O'Donnell, Pattern Matching in Trees (Journal of the ACM, Vol. 29(1), January 1982).Google Scholar
  8. [HMT90]
    Robert Harper, Robin Milner and Mads Tofte, The Definition of Standard ML (The MIT Press).Google Scholar
  9. [Hudak et al 91]
    Paul Hudak et al, Report on the Programming Language Haskell, Version 1.1 (June, 1991).Google Scholar
  10. [Kranz et al 86]
    D. Kranz, R. Kelsey, J. Rees, P. Hudak, J. Philbin, and N. Adams, ORBIT: An optimizing compiler for Scheme (Proceedings SIGPLAN '86 Symposium on Compiler Construction, SIGPLAN Notices, Vol. 21(7), July 1986).Google Scholar
  11. [Peyton Jones 87]
    Simon L. Peyton Jones, The Implementation of Functional Programming Languages (Prentice-Hall, 1987).Google Scholar
  12. [PS90]
    L. Puel and A. Suárez, Compiling Pattern Matching by Term Decomposition (Proceedings of the 1990 ACM Conference on Lisp and Functional Programming).Google Scholar
  13. [Steele78]
    Guy L. Steele Jr., Rabbit: a compiler for Scheme (AI-TR-474, MIT, 1978).Google Scholar
  14. [Wadler87]
    Philip Wadler, Efficient Compilation of Pattern-Matching (Chapter 5 of [Peyton Jones 87]).Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1992

Authors and Affiliations

  • Mikael Pettersson
    • 1
  1. 1.Department of Computer ScienceLinköping UniversitySweden

Personalised recommendations