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 effort of code reuse among similarly structured data. In this paper, we exorcise our datatypes by adapting 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 user can ask the definition of addition to be lifted to lists and she will only be asked the details necessary to carry on adding lists rather than numbers. Our presentation is formalised in a 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]  Conor McBride Ornamental Algebras, Algebraic Ornaments , 2014 .

[2]  Vincent Siles Investigation on the typing of equality in type systems. (Etude sur le typage de l'égalité dans les systèmes de types) , 2010 .

[3]  Robert Harper,et al.  A type-theoretic interpretation of standard ML , 2000, Proof, Language, and Interaction.

[4]  Michael Hedberg,et al.  A coherence theorem for Martin-Löf's type theory , 1998, Journal of Functional Programming.

[5]  Erik Poll,et al.  Algebra of Programming by Richard Bird and Oege de Moor, Prentice Hall, 1996 (dated 1997). , 1999 .

[6]  Johan Jeuring,et al.  Generic programming with fixed points for mutually recursive datatypes , 2009, ICFP.

[7]  Eduardo Giménez,et al.  Codifying Guarded Definitions with Recursive Schemes , 1994, TYPES.

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

[9]  Stephanie Weirich,et al.  Arity-generic datatype-generic programming , 2010, PLPV '10.

[10]  Peter Dybjer,et al.  Representing Inductively Defined Sets by Wellorderings in Martin-Löf's Type Theory , 1997, Theor. Comput. Sci..

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

[12]  J. Lambek A fixpoint theorem for complete categories , 1968 .

[13]  R. Seely,et al.  Locally cartesian closed categories and type theory , 1984, Mathematical Proceedings of the Cambridge Philosophical Society.

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

[15]  Steven Awodey,et al.  Inductive Types in Homotopy Type Theory , 2012, 2012 27th Annual IEEE Symposium on Logic in Computer Science.

[16]  Peter Dybjer,et al.  Universes for Generic Programs and Proofs in Dependent Type Theory , 2003, Nord. J. Comput..

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

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

[19]  E. Wigner The Unreasonable Effectiveness of Mathematics in the Natural Sciences (reprint) , 1960 .

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

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

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

[23]  Gérard P. Huet,et al.  The Zipper , 1997, Journal of Functional Programming.

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

[25]  Joyce L. Vedral,et al.  Functional Programming Languages and Computer Architecture , 1989, Lecture Notes in Computer Science.

[26]  Bruno C. d. S. Oliveira,et al.  Comparing libraries for generic programming in haskell , 2008, Haskell '08.

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

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

[29]  Peter Dybjer,et al.  Internal Type Theory , 1995, TYPES.

[30]  David Walker,et al.  A Concurrent Logical Framework: The Propositional Fragment , 2003, TYPES.

[31]  Peter Hancock,et al.  Programming interfaces and basic topology , 2009, Ann. Pure Appl. Log..

[32]  Robin O. Gandy,et al.  On the axiom of extensionality – Part I , 1956, Journal of Symbolic Logic.

[33]  Thorsten Altenkirch,et al.  Containers: Constructing strictly positive types , 2005, Theor. Comput. Sci..

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

[35]  Erik Palmgren,et al.  Wellfounded trees in categories , 2000, Ann. Pure Appl. Log..

[36]  S. Awodey,et al.  Homotopy theoretic models of identity types , 2007, Mathematical Proceedings of the Cambridge Philosophical Society.

[37]  Peter Dybjer,et al.  Inductive families , 2005, Formal Aspects of Computing.

[38]  Matthieu Sozeau Equations: A Dependent Pattern-Matching Compiler , 2010, ITP.

[39]  Gang Chen,et al.  Guarded recursive datatype constructors , 2003, POPL '03.

[40]  Herman Geuvers,et al.  Induction Is Not Derivable in Second Order Dependent Type Theory , 2001, TLCA.

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

[42]  Christine C. Paulin Extraction de programmes dans le calcul des constructions , 1989 .

[43]  Robert Atkey,et al.  When Is a Type Refinement an Inductive Type? , 2011, FoSSaCS.

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

[45]  Andrew M. Pitts,et al.  Polymorphism is Set Theoretic, Constructively , 1987, Category Theory and Computer Science.

[46]  Gordon D. Plotkin,et al.  The category-theoretic solution of recursive domain equations , 1977, 18th Annual Symposium on Foundations of Computer Science (sfcs 1977).

[47]  Michael Shulman,et al.  Framed bicategories and monoidal fibrations , 2007, 0706.1286.

[48]  Mads Tofte,et al.  A Type-Theoretic Interpretation of Standard ML , 2000 .

[49]  John C. Reynolds,et al.  Polymorphism is not Set-Theoretic , 1984, Semantics of Data Types.

[50]  Alexandre Miquel The Implicit Calculus of Constructions , 2001, TLCA.

[51]  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 .

[52]  Peter Dybjer,et al.  The Biequivalence of Locally Cartesian Closed Categories and Martin-Löf Type Theories , 2014, Math. Struct. Comput. Sci..

[53]  Martin Hofmann,et al.  On the Interpretation of Type Theory in Locally Cartesian Closed Categories , 1994, CSL.

[54]  Gordon D. Plotkin,et al.  Abstract syntax and variable binding , 1999, Proceedings. 14th Symposium on Logic in Computer Science (Cat. No. PR00158).

[55]  Erik Palmgren,et al.  On Universes in Type Theory , 2011 .

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

[57]  Edsko de Vries,et al.  Formal polytypic programs and proofs , 2010, Journal of Functional Programming.

[58]  Patricia Johann,et al.  Indexed Induction and Coinduction, Fibrationally , 2011, CALCO.

[59]  P. Martin-Löf An Intuitionistic Theory of Types: Predicative Part , 1975 .

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

[61]  Richard Garner On the strength of dependent products in the type theory of Martin-Löf , 2009, Ann. Pure Appl. Log..

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

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

[64]  F. William Lawvere,et al.  Adjointness in Foundations , 1969 .

[65]  Harald Ruess,et al.  Polytypic Proof Construction , 1999, TPHOLs.

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

[67]  P. Martin-Löf On the meanings of the logical constants and the justi cations of the logical laws , 1996 .

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

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

[70]  N. Gambino,et al.  Polynomial functors and polynomial monads , 2009, Mathematical Proceedings of the Cambridge Philosophical Society.

[71]  Andrew D. Gordon,et al.  Refinement Types for Secure Implementations , 2008, 2008 21st IEEE Computer Security Foundations Symposium.

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

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

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

[75]  Karl Crary Carnegie Explicit Contexts in LF , 2008 .

[76]  Conor McBride,et al.  Transporting functions across ornaments , 2014, J. Funct. Program..

[77]  Per Martin-Löf,et al.  Constructive mathematics and computer programming , 1984 .

[78]  Guy L. Steele,et al.  Growing a Language , 1999, High. Order Symb. Comput..

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

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

[81]  Robert Harper,et al.  2-Dimensional Directed Type Theory , 2011, MFPS.

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

[83]  Mogens Nielsen,et al.  Foundations of Software Science and Computation Structures , 2002, Lecture Notes in Computer Science.

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

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

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