Inductive data such as finite lists and trees can elegantly be defined by constructors which allow programmers to analyze and manipulate finite data via pattern matching. Dually, coinductive data such as streams can be defined by observations such as head and tail and programmers can synthesize infinite data via copattern matching. This leads to a symmetric language where finite and infinite data can be nested. In this paper, we compile nested pattern and copattern matching into a core language which only supports simple non-nested (co)pattern matching. This core language may serve as an intermediate language of a compiler. We show that this translation is conservative, i.e. the multi-step reduction relation in both languages coincides for terms of the original language. Furthermore, we show that the translation preserves strong and weak normalisation: a term of the original language is strongly/weakly normalising in one language if and only if it is so in the other. In the proof we develop more general criteria which guarantee that extensions of abstract reduction systems are conservative and preserve strong or weak normalisation.


Pattern matching copattern matching algebraic data types codata coalgebras conservative extension strong normalisation weak normalisation abstract reduction system ARS 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Abel, A.: A Polymorphic Lambda-Calculus with Sized Higher-Order Types. PhD thesis, Ludwig-Maximilians-Universität München (2006)Google Scholar
  2. 2.
    Abel, A., Pientka, B., Thibodeau, D., Setzer, A.: Copatterns: Programming infinite structures by observations. In: Proc. of the 40th ACM Symp. on Principles of Programming Languages, POPL 2013, pp. 27–38. ACM Press (2013)Google Scholar
  3. 3.
    Augustsson, L.: Compiling pattern matching. In: Jouannaud, J.-P. (ed.) FPCA 1985. LNCS, vol. 201, pp. 368–381. Springer, Heidelberg (1985)CrossRefGoogle Scholar
  4. 4.
    Barthe, G., Frade, M.J., Giménez, E., Pinto, L., Uustalu, T.: Type-based termination of recursive definitions. Math. Struct. in Comput. Sci. 14(1), 97–141 (2004)CrossRefzbMATHGoogle Scholar
  5. 5.
    Brady, E.: Idris, a general purpose dependently typed programming language: Design and implementation (2013),
  6. 6.
    Cockett, R., Fukushima, T.: About Charity. Technical report, Department of Computer Science, The University of Calgary, Yellow Series Report No. 92/480/18 (June 1992)Google Scholar
  7. 7.
    Hagino, T.: A typed lambda calculus with categorical type constructors. In: Pitt, D.H., Rydeheard, D.E., Poigné, A. (eds.) Category Theory and Computer Science. LNCS, vol. 283, pp. 140–157. Springer, Heidelberg (1987)CrossRefGoogle Scholar
  8. 8.
    Hagino, T.: Codatatypes in ML. J. Symb. Logic 8(6), 629–650 (1989)zbMATHMathSciNetGoogle Scholar
  9. 9.
    INRIA. The Coq Proof Assistant Reference Manual. INRIA, version 8.4 edition (2012)Google Scholar
  10. 10.
    Norell, U.: Towards a Practical Programming Language Based on Dependent Type Theory. PhD thesis, Dept. of Computer Science and Engineering, Chalmers, Göteborg, Sweden (2007)Google Scholar
  11. 11.
    Severi, P.G.: Normalisation in lambda calculus and its relation to type inference. PhD thesis, Technische Universiteit Eindhoven, Eindhoven, The Netherlands (1996)Google Scholar
  12. 12.
    Terese. Term Rewriting Systems. Cambridge University Press (2003)Google Scholar
  13. 13.
    van Raamsdonk, F.: Concluence and Normalisation for Higher-Order Rewriting. PhD thesis, Vrije Universiteit, Amsterdam, The Netherlands (1996)Google Scholar

Copyright information

© Springer International Publishing Switzerland 2014

Authors and Affiliations

  • Anton Setzer
    • 1
  • Andreas Abel
    • 2
  • Brigitte Pientka
    • 3
  • David Thibodeau
    • 3
  1. 1.Dept. of Computer ScienceSwansea UniversitySwanseaUK
  2. 2.Computer Science and EngineeringChalmers and Gothenburg UniversityGöteborgSweden
  3. 3.School of Computer ScienceMcGill UniversityMontrealCanada

Personalised recommendations