Refactoring pattern matching

Defining functions by pattern matching over the arguments is advantageous for understanding and reasoning, but it tends to expose the implementation of a datatype. Significant effort has been invested in tackling this loss of modularity; however, decoupling patterns from concrete representations while maintaining soundness of reasoning has been a challenge. Inspired by the development of invertible programming, we propose an approach to program refactoring based on a right-invertible language rinv-every function has a right (or pre-) inverse. We show how this new design is able to permit a smooth incremental transition from programs with algebraic datatypes and pattern matching, to ones with proper encapsulation, while maintaining simple and sound reasoning.

[1]  Ricardo Peña-Marí,et al.  A new look at pattern matching in abstract data types , 1996, ICFP '96.

[2]  Guy L. Steele,et al.  Organizing functional code for parallel execution or, foldl and foldr considered slightly harmful , 2009, ICFP.

[3]  Benjamin C. Pierce,et al.  Combinators for bi-directional tree transformations: a linguistic approach to the view update problem , 2005, POPL '05.

[4]  Rod M. Burstall,et al.  HOPE: An experimental applicative language , 1980, LISP Conference.

[5]  Lambert Meertens,et al.  Algorithmics : towards programming as a mathematical activity , 1986 .

[6]  Giuseppe Castagna,et al.  Semantic subtyping: Dealing set-theoretically with function, union, intersection, and negation types , 2008, JACM.

[7]  T. Sheard Template Metaprogramming for Haskell , 2014 .

[8]  Richard S. Bird,et al.  An introduction to the theory of lists , 1987 .

[9]  John Hughes,et al.  Generalising monads to arrows , 2000, Sci. Comput. Program..

[10]  Marko C. J. D. van Eekelen,et al.  There and back again: arrows for invertible programming , 2005, Haskell '05.

[11]  Kazutaka Matsuda,et al.  Gradual Refinement , 2010, MPC.

[12]  Juan José Moreno-Navarro,et al.  Bialgebra views: a way for polytypic programming to cohabit with data abstraction , 2008, WGP '08.

[13]  Tarmo Uustalu,et al.  Primitive (Co)Recursion and Course-of-Value (Co)Iteration, Categorically , 1999, Informatica.

[14]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

[15]  Roman Leshchinskiy,et al.  Stream fusion: from lists to streams to nothing at all , 2007, ICFP '07.

[16]  Damien Sereni,et al.  Termination analysis and call graph construction for higher-order functional programs , 2007, ICFP '07.

[17]  Martin Erwig,et al.  Active Patterns , 1996, Implementation of Functional Languages.

[18]  Venanzio Capretta,et al.  Recursive Coalgebras from Comonads , 2004, CMCS.

[19]  Don Syme,et al.  Extensible pattern matching via a lightweight language extension , 2007, ICFP '07.

[20]  Stephen N. Zilles,et al.  Programming with abstract data types , 1974, SIGPLAN Symposium on Very High Level Languages.

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

[22]  C. A. R. Hoare,et al.  Proof of correctness of data representations , 1972, Acta Informatica.

[23]  Simon L. Peyton Jones,et al.  Template meta-programming for Haskell , 2002, Haskell '02.

[24]  Robin Milner,et al.  An Algebraic Definition of Simulation Between Programs , 1971, IJCAI.

[25]  Janis Voigtländer Bidirectionalization for free! (Pearl) , 2009, POPL '09.

[26]  Benjamin C. Pierce,et al.  Quotient lenses , 2008, ICFP.

[27]  Simon L. Peyton Jones,et al.  Pattern Guards and Transformational Patterns , 2000, Electron. Notes Theor. Comput. Sci..

[28]  M. R. Sleep,et al.  A short note concerning lazy reduction rules for append , 1982 .

[29]  Robert Glück,et al.  The universal resolving algorithm and its correctness: inverse computation in a functional language , 2002, Sci. Comput. Program..

[30]  Maarten M. Fokkinga,et al.  Program Calculation Properties of Continuous Algebras , 1991 .

[31]  Benjamin C. Pierce,et al.  Boomerang: resourceful lenses for string data , 2008, POPL '08.

[32]  Christophe Ringeissen,et al.  A Pattern Matching Compiler for Multiple Target Languages , 2003, CC.

[33]  Akimasa Morihata,et al.  Automatic inversion generates divide-and-conquer parallel programs , 2007, PLDI '07.

[34]  Shin-Cheng Mu,et al.  An Injective Language for Reversible Computation , 2004, MPC.

[35]  Richard S. Bird The promotion and accumulation strategies in transformational programming , 1984, TOPL.

[36]  Nicole Stender Template Metaprogramming for Haskell , 2014 .

[37]  Richard S. Bird,et al.  Algebra of programming , 1997, Prentice Hall International series in computer science.

[38]  Shin-Cheng Mu,et al.  A Grammar-Based Approach to Invertible Programs , 2010, ESOP.

[39]  C. Barry Jay,et al.  The pattern calculus , 2004, TOPL.

[40]  Shin-Cheng Mu,et al.  A programmable editor for developing structured documents based on bidirectional transformations , 2004, PEPM '04.

[41]  Lambert G. L. T. Meertens,et al.  Paramorphisms , 2005, Formal Aspects of Computing.

[42]  Maarten M. Fokkinga,et al.  Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire , 1991, FPCA.

[43]  Shin-Cheng Mu,et al.  Theory and applications of inverting functions as folds , 2004, Sci. Comput. Program..

[44]  Philip Wadler,et al.  Deforestation: Transforming Programs to Eliminate Trees , 1990, Theor. Comput. Sci..

[45]  Alcino Cunha,et al.  Generic Point-free Lenses , 2010, MPC.

[46]  N. Falconer Structured Programming , 1973, Nature.

[47]  Chris Okasaki Views for Standard ML , 2011 .

[48]  Niklaus Wirth,et al.  Program development by stepwise refinement , 1971, CACM.

[49]  Mark Tullsen,et al.  First Class Patterns , 2000, PADL.

[50]  Manfred Broy,et al.  Logic of Programming and Calculi of Discrete Design , 1987, NATO ASI Series.

[51]  Philip Wadler,et al.  A critique of Abelson and Sussman or why calculating is better than scheming , 1987, SIGP.

[52]  F. Warren Burton,et al.  Pattern matching with abstract data types , 1993, Journal of Functional Programming.

[53]  Costas S. Iliopoulos,et al.  Formal Aspects of Computing , 2013 .

[54]  Philip Wadler The Concatenate Vanishes , 1987 .

[55]  Neil D. Jones,et al.  The size-change principle for program termination , 2001, POPL '01.

[56]  Benjamin C. Pierce,et al.  Updatable Security Views , 2009, 2009 22nd IEEE Computer Security Foundations Symposium.

[57]  Barbara Liskov,et al.  Program Development in Java - Abstraction, Specification, and Object-Oriented Design , 1986 .

[58]  Robert Glück,et al.  An Universal Resolving Algorithm for Inverse Computation of Lazy Languages , 2006, Ershov Memorial Conference.

[59]  Shin-Cheng Mu,et al.  An Algebraic Approach to Bi-directional Updating , 2004, APLAS.

[60]  Chris Okasaki,et al.  An Overview of Edison , 2001, Haskell.

[61]  Robert Glück,et al.  A positive supercompiler , 1996, Journal of Functional Programming.

[62]  Kazutaka Matsuda,et al.  Bidirectionalization transformation based on automatic derivation of view complement functions , 2007, ICFP '07.

[63]  Germán Vidal,et al.  The narrowing-driven approach to functional logic program specialization , 2009, New Generation Computing.

[64]  Philip Wadler,et al.  Views: a way for pattern matching to cohabit with data abstraction , 1987, POPL '87.

[65]  Martin Odersky,et al.  Matching Objects with Patterns , 2007, ECOOP.

[66]  Meng Wang,et al.  Combining syntactic and semantic bidirectionalization , 2010, ICFP '10.