Transporting functions across ornaments

Programming with dependent types is a blessing and a curse. It is a blessing to be able to bake invariants into the definition of datatypes: We can finally write correct-by-construction software. However, this extreme accuracy is also a curse: A datatype is the combination of a structuring medium together with a special purpose logic. These domain-specific logics hamper any attempt to reuse code across similarly structured data. In this paper, we capitalise on the structural invariants of datatypes. To do so, we first adapt the notion of ornament to our universe of inductive families. We then show how code reuse can be achieved by ornamenting functions. Using these functional ornaments, we capture the relationship between functions such as the addition of natural numbers and the concatenation of lists. With this knowledge, we demonstrate how the implementation of the former informs the implementation of the latter: The users can ask the definition of addition to be lifted to lists and they will only be asked the details necessary to carry on adding lists rather than numbers. Our presentation is formalised in the type theory with a universe of datatypes and all our constructions have been implemented as generic programs, requiring no extension to the type theory.

[1]  Martin Hofmann,et al.  The groupoid model refutes uniqueness of identity proofs , 1994, Proceedings Ninth Annual IEEE Symposium on Logic in Computer Science.

[2]  Frank Pfenning,et al.  Refinement types for ML , 1991, PLDI '91.

[3]  Conor McBride,et al.  The view from the left , 2004, Journal of Functional Programming.

[4]  Jean-Philippe Bernardy,et al.  Realizability and Parametricity in Pure Type Systems , 2011, FoSSaCS.

[5]  Conor McBride,et al.  Dependently typed functional programs and their proofs , 2000 .

[6]  Edwin Brady,et al.  Scrapping your inefficient engine: using partial evaluation to improve domain-specific language implementation , 2010, ICFP '10.

[7]  James Cheney,et al.  First-Class Phantom Types , 2003 .

[8]  Fredrik Lindblad,et al.  A Tool for Automated Theorem Proving in Agda , 2004, TYPES.

[9]  Conor McBride,et al.  Elimination with a Motive , 2000, TYPES.

[10]  Christine Paulin-Mohring Extraction de programmes dans le Calcul des Constructions. (Program Extraction in the Calculus of Constructions) , 1989 .

[11]  Conor McBride,et al.  Transporting functions across ornaments , 2012, ICFP '12.

[12]  Conor McBride,et al.  A Categorical Treatment of Ornaments , 2012, 2013 28th Annual ACM/IEEE Symposium on Logic in Computer Science.

[13]  Chung-Kil Hur,et al.  Strongly Typed Term Representations in Coq , 2011, Journal of Automated Reasoning.

[14]  Robert Atkey,et al.  Refining Inductive Types , 2012, Log. Methods Comput. Sci..

[15]  Jeremy Gibbons,et al.  Modularising inductive families , 2011, WGP@ICFP.

[16]  Conor McBride,et al.  A Few Constructions on Constructors , 2004, TYPES.

[17]  Bart Jacobs,et al.  Structural Induction and Coinduction in a Fibrational Setting , 1998, Inf. Comput..

[18]  Peter Morris,et al.  The gentle art of levitation , 2010, ICFP '10.

[19]  Jean-Philippe Bernardy,et al.  A Theory of Parametric Polymorphism and an Application ; A formalisation of parametric polymorphism within and about dependent type-theory, and an application to property-based testing , 2011 .

[20]  Pierre-Yves Strub,et al.  Coq Modulo Theory , 2010, CSL.

[21]  Simon L. Peyton Jones,et al.  Complete and decidable type inference for GADTs , 2009, ICFP.

[22]  Enrico Tassi,et al.  A Small Scale Reflection Extension for the Coq system , 2008 .

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

[24]  Peter Morris,et al.  A Universe of Strictly Positive Families , 2009, Int. J. Found. Comput. Sci..

[25]  Philip Wadler,et al.  Theorems for free! , 1989, FPCA.

[26]  Juan Chen,et al.  Secure distributed programming with value-dependent types , 2011, Journal of Functional Programming.

[27]  Clément Fumex Induction and coinduction schemes in category theory , 2012 .

[28]  Conor McBride,et al.  Inductive Families Need Not Store Their Indices , 2003, TYPES.

[29]  Jean-Philippe Bernardy,et al.  Type-theory in color , 2013, ICFP.