Unnesting of Copatterns
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.
KeywordsPattern 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.
- 1.Abel, A.: A Polymorphic Lambda-Calculus with Sized Higher-Order Types. PhD thesis, Ludwig-Maximilians-Universität München (2006)Google Scholar
- 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
- 5.Brady, E.: Idris, a general purpose dependently typed programming language: Design and implementation (2013), http://www.cs.st-andrews.ac.uk/~eb/drafts/impldtp.pdf
- 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
- 9.INRIA. The Coq Proof Assistant Reference Manual. INRIA, version 8.4 edition (2012)Google Scholar
- 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.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.Terese. Term Rewriting Systems. Cambridge University Press (2003)Google Scholar
- 13.van Raamsdonk, F.: Concluence and Normalisation for Higher-Order Rewriting. PhD thesis, Vrije Universiteit, Amsterdam, The Netherlands (1996)Google Scholar