Copatterns: programming infinite structures by observations

Inductive datatypes provide mechanisms to define finite data such as finite lists and trees via constructors and allow programmers to analyze and manipulate finite data via pattern matching. In this paper, we develop a dual approach for working with infinite data structures such as streams. Infinite data inhabits coinductive datatypes which denote greatest fixpoints. Unlike finite data which is defined by constructors we define infinite data by observations. Dual to pattern matching, a tool for analyzing finite data, we develop the concept of copattern matching, which allows us to synthesize infinite data. This leads to a symmetric language design where pattern matching on finite and infinite data can be mixed. We present a core language for programming with infinite structures by observations together with its operational semantics based on (co)pattern matching and describe coverage of copatterns. Our language naturally supports both call-by-name and call-by-value interpretations and can be seamlessly integrated into existing languages like Haskell and ML. We prove type soundness for our language and sketch how copatterns open new directions for solving problems in the interaction of coinductive and dependent types.

[1]  J. Granström,et al.  Reference and Computation in Intuitionistic Type Theory , 2008 .

[2]  Thorsten Altenkirch,et al.  Termination Checking in the Presence of Nested Inductive and Coinductive Types , 2010, PAR@ITP.

[3]  Thorsten Altenkirch,et al.  Subtyping, Declaratively , 2010, MPC.

[4]  Philip Wadler Call-by-Value Is Dual to Call-by-Name - Reloaded , 2005, RTA.

[5]  Jérôme Vouillon,et al.  Semantic types: a fresh look at the ideal model for types , 2004, POPL '04.

[6]  Neelakantan R. Krishnaswami Focusing on pattern matching , 2009, POPL '09.

[7]  Hugo Herbelin,et al.  The duality of computation , 2000, ICFP '00.

[8]  Luís Pinto,et al.  Type-based termination of recursive definitions , 2004, Mathematical Structures in Computer Science.

[9]  Tatsuya Hagino,et al.  Codatatypes in ML , 1989, J. Symb. Comput..

[10]  Brigitte Pientka,et al.  Case Analysis of Higher-Order Data , 2009, Electron. Notes Theor. Comput. Sci..

[11]  Thorsten Altenkirch,et al.  Subtyping, declaratively: an exercise in mixed induction and coinduction , 2010, MPC'10 2010.

[12]  Tatsuya Hagino,et al.  A Typed Lambda Calculus with Categorical Type Constructors , 1987, Category Theory and Computer Science.

[13]  Noam Zeilberger,et al.  Focusing and higher-order abstract syntax , 2008, POPL '08.

[14]  U. Norell,et al.  Towards a practical programming language based on dependent type theory , 2007 .

[15]  P. Medawar A view from the left , 1984, Nature.

[16]  Matthias Felleisen,et al.  A Syntactic Approach to Type Soundness , 1994, Inf. Comput..

[17]  Eduardo Giménez,et al.  Un calcul de constructions infinies et son application a la verification de systemes communicants , 1996 .

[18]  Noam Zeilberger On the unity of duality , 2008, Ann. Pure Appl. Log..

[19]  Conor McBride,et al.  Eliminating Dependent Pattern Matching , 2006, Essays Dedicated to Joseph A. Goguen.

[20]  Benjamin C. Pierce,et al.  Local type inference , 1998, POPL '98.

[21]  Christine Paulin-Mohring,et al.  The coq proof assistant reference manual , 2000 .

[22]  Anton Setzer,et al.  Coalgebras as Types Determined by Their Elimination Rules , 2012, Epistemology versus Ontology.

[23]  Andreas Abel Mixed Inductive/Coinductive Types and Strong Normalization , 2007, APLAS.

[24]  Frank Pfenning,et al.  A Coverage Checking Algorithm for LF , 2003, TPHOLs.

[25]  Robert L. Constable,et al.  Infinite Objects in Type Theory , 1986, LICS.

[26]  Martín Abadi,et al.  A Theory of Primitive Objects - Untyped and First-Order Systems , 1994, TACS.

[27]  Thierry Coquand,et al.  Pattern Matching with Dependent Types , 1992 .

[28]  JEAN-MARC ANDREOLI,et al.  Logic Programming with Focusing Proofs in Linear Logic , 1992, J. Log. Comput..

[29]  Andreas Abel Type-Based Termination, Inflationary Fixed-Points, and Mixed Inductive-Coinductive Types , 2012, FICS.

[30]  Noam Zeilberger,et al.  Focusing on Binding and Computation , 2008, 2008 23rd Annual IEEE Symposium on Logic in Computer Science.

[31]  Michel Parigot,et al.  Proofs of strong normalisation for second order classical natural deduction , 1997, Journal of Symbolic Logic.

[32]  Daisuke Kimura,et al.  Dual Calculus with Inductive and Coinductive Types , 2009, RTA.

[33]  Nick Benton,et al.  A Term Calculus for Intuitionistic Linear Logic , 1993, TLCA.

[34]  Robin Milner,et al.  A Theory of Type Polymorphism in Programming , 1978, J. Comput. Syst. Sci..

[35]  Philip Wadler,et al.  Call-by-Value Is Dual to Call-by-Name - Reloaded , 2005, RTA.

[36]  Amr Sabry,et al.  Proving the correctness of reactive systems using sized types , 1996, POPL '96.

[37]  Conor McBride,et al.  Let's See How Things Unfold: Reconciling the Infinite with the Intensional (Extended Abstract) , 2009, CALCO.

[38]  Noam Zeilberger,et al.  The logical basis of evaluation order and pattern-matching , 2009 .