Translation Correctness for First-Order Object-Oriented Pattern Matching

  • Burak Emir
  • Qin Ma
  • Martin Odersky
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4807)


Pattern matching makes ML programs more concise and readable, and these qualities are also sought in object-oriented settings. However, objects and classes come with open class hierarchies, extensibility requirements and the need for data abstraction, which all conflict with matching on concrete data types. Extractor-based pattern matching has been proposed to address this conflict. Extractors are user-defined methods that perform the task of value discrimination and deconstruction during pattern matching. In this paper, we give the first formalization of extractor-based matching, using a first-order object-oriented calculus. We give a direct operational semantics and prove it sound. We then present an optimizing translation to a target language without matching, and prove a correctness result stating that an expression is equivalent to its translation.


Pattern Match Operational Semantic Data Abstraction Typing Rule Test Expression 
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.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Burstall, R.M.: Proving properties of programs by inductive definitions. Computer 41–48 (1969)Google Scholar
  2. 2.
    Wadler, P.: Pattern Matching. In: ch. 4 of Peyton Jones, Wadler ”Implementation of Functional Programming Languages”, Prentice Hall, Englewood Cliffs (1987)Google Scholar
  3. 3.
    Field, A., Harrison, P.: Functional Programming. Addison-Wesley, Reading (1988)zbMATHGoogle Scholar
  4. 4.
    Pettersson, M.: A term pattern-match compiler inspired by finite-automata theory. In: Pfahler, P., Kastens, U. (eds.) CC 1992. LNCS, vol. 641, Springer, Heidelberg (1992)Google Scholar
  5. 5.
    Scott, K., Ramsey, N.: When do match-compilation heuristics matter? Technical Report CS-2000-13, University of Virginia (2000)Google Scholar
  6. 6.
    Fessant, F.L., Maranget, L.: Optimizing pattern matching. In: ICFP, pp. 26–37 (2001)Google Scholar
  7. 7.
    Wadler, P.: Views: A way for pattern matching to cohabit with data abstraction. In: POPL (1987)Google Scholar
  8. 8.
    Okasaki, C.: Views for Standard ML. In: Proceedings of SIGPLAN Workshop on ML, pp. 14–23 (1998)Google Scholar
  9. 9.
    Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns. Addison-Wesley, Reading (1995)Google Scholar
  10. 10.
    Emir, B., Williams, J., Odersky, M.: Matching objects with patterns. In: ECOOP 2007. LNCS, vol. 4609, Springer, Heidelberg (2007)CrossRefGoogle Scholar
  11. 11.
    Syme, D., Neverov, G., Margetson, J.: Extensible Pattern Matching via a Lightweight Language Extension. In: ICFP (2007)Google Scholar
  12. 12.
    Igarashi, A., Pierce, B., Wadler, P.: Featherweight Java. In: OOPSLA (1999)Google Scholar
  13. 13.
    Emir, B.: Object-Oriented Pattern Matching. PhD thesis, EPFL Lausanne (2007)Google Scholar
  14. 14.
    Leroy, X., Grall, H.: Coinductive big-step operational semantics. Theoretical Computer Science (submitted)Google Scholar
  15. 15.
    Ma, Q.: Concurrent Classes and Pattern Matching in the Join Calculus. PhD thesis, INRIA-Rocquencourt and University Paris 7 (2005)Google Scholar
  16. 16.
    Maranget, L.: Warnings in pattern matching. Journal of Functional Programming 17(3), 387–421 (2007)zbMATHCrossRefMathSciNetGoogle Scholar
  17. 17.
    Gostanza, P.P., Pena, R., Nunez, M.M.: A new look at pattern matching in abstract data types. In: ICFP (1996)Google Scholar
  18. 18.
    Zenger, M., Odersky, M.: Extensible algebraic datatypes with defaults. In: ICFP (2001)Google Scholar
  19. 19.
    Liu, J., Myers, A.C.: JMatch: Iterable Abstract Pattern Matching for Java. In: Dahl, V., Wadler, P. (eds.) PADL 2003. LNCS, vol. 2562, pp. 110–127. Springer, Heidelberg (2002)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2007

Authors and Affiliations

  • Burak Emir
    • 1
  • Qin Ma
    • 2
  • Martin Odersky
    • 1
  1. 1.EPFL, 1015 LausanneSwitzerland
  2. 2.OFFIS, Escherweg 2, OldenburgGermany

Personalised recommendations