Skip to main content

ML pattern match compilation and partial evaluation

  • Conference paper
  • First Online:
Partial Evaluation

Part of the book series: Lecture Notes in Computer Science ((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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  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. M. Baudinet and D. MacQueen. Tree pattern matching for ML (extended abstract). Draft paper, AT&T Bell Laboratories, 1985.

    Google Scholar 

  3. C. Consel and O. Danvy. Partial evaluation of pattern matching in strings. Information Processing Letters, 30:79–86, January 1989.

    Google Scholar 

  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. 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. 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. 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. N.D. Jones, C.K. Gomard, and P. Sestoft. Partial Evaluation and Automatic Program Generation. Prentice-Hall, 1993.

    Google Scholar 

  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. 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. 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. 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. X. Leroy. The Zinc experiment: An economical implementation of the ML language. Rapport Technique 117, INRIA Rocquencourt, France, 1990.

    Google Scholar 

  14. R. Milner, M. Tofte, and R. Harper. The Definition of Standard ML. MIT Press, 1990.

    Google Scholar 

  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. S.L. Peyton Jones. The Implementation of Functional Programming Languages. Prentice-Hall, 1987.

    Google Scholar 

  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. 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. J. Reppy. Personal communication, November 1995.

    Google Scholar 

  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. 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 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Olivier Danvy Robert Glück Peter Thiemann

Rights and permissions

Reprints and permissions

Copyright information

© 1996 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Sestoft, P. (1996). ML pattern match compilation and partial evaluation. In: Danvy, O., Glück, R., Thiemann, P. (eds) Partial Evaluation. Lecture Notes in Computer Science, vol 1110. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-61580-6_22

Download citation

  • DOI: https://doi.org/10.1007/3-540-61580-6_22

  • Published:

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-61580-4

  • Online ISBN: 978-3-540-70589-5

  • eBook Packages: Springer Book Archive

Publish with us

Policies and ethics