Advertisement

ML pattern match compilation and partial evaluation

  • Peter Sestoft
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 1110)

Abstract

We derive a compiler for ML-style pattern matches. It is conceptually simple and produces reasonably good compiled matches. The derivation is inspired by the instrumentation and partial evaluation of naÏve string matchers. Following that paradigm, we first present a general and naÏve ML pattern matcher, instrument it to collect and exploit extra information, and show that partial evaluation of the instrumented general matcher with respect to a given match produces an efficient specialized matcher.

We then discard the partial evaluator and show that a match compiler can be obtained just by slightly modifying the instrumented general matcher. The resulting match compiler is interesting in its own right, and naturally detects inexhaustive matches and redundant match rules.

Keywords

Pattern Match Partial Evaluation Negative Information Term Description Match Rule 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    L. Augustsson. Compiling pattern matching. In Jean-Pierre Jouannaud, editor, Functional Programming Languages and Computer Architecture, Nancy, France, September 1985. (Lecture Notes in Computer Science, vol. 201), pages 368–381. Springer-Verlag, 1985.Google Scholar
  2. 2.
    M. Baudinet and D. MacQueen. Tree pattern matching for ML (extended abstract). Draft paper, AT&T Bell Laboratories, 1985.Google Scholar
  3. 3.
    C. Consel and O. Danvy. Partial evaluation of pattern matching in strings. Information Processing Letters, 30:79–86, January 1989.Google Scholar
  4. 4.
    Y. Futamura and K. Nogi. Generalized partial computation. In D. Bjørner, A.P. Ershov, and N.D. Jones, editors, Partial Evaluation and Mixed Computation, pages 133–151. Amsterdam: North-Holland, 1988.Google Scholar
  5. 5.
    R. Glück and J. Jørgensen. Generating optimizing specializes. In IEEE Computer Society International Conference on Computer Languages, Toulouse, France, 1994, pages 183–194. IEEE Computer Society Press, 1994.Google Scholar
  6. 6.
    P. Hudak, S. Peyton Jones, P. Wadler, et al. Report on the programming language Haskell — a non-strict, purely functional language, version 1.2. SIGPLAN Notices, 27(5):R1–R162, May 1992.Google Scholar
  7. 7.
    G. Huet and J.-J. Lévy. Call by need computations in non-ambiguous linear term rewriting systems. Rapport de Recherche 359, IRIA Rocquencourt, France, 1979.Google Scholar
  8. 8.
    N.D. Jones, C.K. Gomard, and P. Sestoft. Partial Evaluation and Automatic Program Generation. Prentice-Hall, 1993.Google Scholar
  9. 9.
    J. Jørgensen. Generating a pattern matching compiler by partial evaluation. In S.L. Peyton Jones, G. Hutton, and C. Kehler Holst, editors, Functional Programming, Glasgow 1990, pages 177–195. Berlin: Springer-Verlag, 1991.Google Scholar
  10. 10.
    J. Jørgensen. Compiler generation by partial evaluation. Master's thesis, DIKU, University of Copenhagen, Denmark, 1992. Student Project 92-1-4.Google Scholar
  11. 11.
    D.E. Knuth, J.H. Morris, and V.R. Pratt. Past pattern matching in strings. SIAM Journal of Computation, 6(2):323–350, 1977.Google Scholar
  12. 12.
    A. Laville. Implementation of lazy pattern matching algorithms. In H. Ganzinger, editor, ESOP'88, 2nd European Symposium on Programming, Nancy, France, March 1988, pages 298–316. Berlin: Springer-Verlag, 1988.Google Scholar
  13. 13.
    X. Leroy. The Zinc experiment: An economical implementation of the ML language. Rapport Technique 117, INRIA Rocquencourt, France, 1990.Google Scholar
  14. 14.
    R. Milner, M. Tofte, and R. Harper. The Definition of Standard ML. MIT Press, 1990.Google Scholar
  15. 15.
    M. Petterson. A term pattern-match compiler inspired by finite automata theory. In U. Kastens and P. Pfahler, editors, Compiler Construction, Paderborn, Germany, October 1992 (Lecture Notes in Computer Science, vol. 641). Berlin: Springer-Verlag, 1992.Google Scholar
  16. 16.
    S.L. Peyton Jones. The Implementation of Functional Programming Languages. Prentice-Hall, 1987.Google Scholar
  17. 17.
    L. Puel and A. Suárez. Compiling pattern matching by term decomposition. Journal of Symbolic Computation, 15(1):1–26, January 1993.Google Scholar
  18. 18.
    R. Ramesh, I.V. Ramakrishnan, and D.S. Warren. Automata-driven indexing of prolog clauses. Journal of Logic Programming, 23(3):151–202, 1995.Google Scholar
  19. 19.
    J. Reppy. Personal communication, November 1995.Google Scholar
  20. 20.
    S. Romanenko and P. Sestoft. Moscow ML Language Overview, version 1.31, October 1995. Available as ftp://ftp.dina.kvl.dk/pub/mosml/doc/mosmlref.ps.Z.Google Scholar
  21. 21.
    S. Romanenko and P. Sestoft. Moscow ML Owner's Manual, version 1.31, October 1995. Available as ftp://ftp.dina.kvl.dk/pub/mosml/doc/manual.ps.Z.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1996

Authors and Affiliations

  • Peter Sestoft
    • 1
  1. 1.Department of Mathematics and PhysicsRoyal Veterinary and Agricultural UniversityFrederiksberg CDenmark

Personalised recommendations