Abstract
Some parts of dependently typed programs constitute evidence of their type-correctness and, once checked, are unnecessary for execution. These parts can easily become asymptotically larger than the remaining runtime-useful computation, which can cause normally linear-time programs run in exponential time, or worse. We should not make programs run slower by just describing them more precisely.
Current dependently typed systems do not erase such computation satisfactorily. By modelling erasure indirectly through type universes or irrelevance, they impose the limitations of these means to erasure. Some useless computation then cannot be erased and idiomatic programs remain asymptotically sub-optimal.
In this paper, we explain why we need erasure, that it is different from other concepts like irrelevance, and propose a dependently typed calculus with pattern matching with erasure annotations to model it. We show that erasure in well-typed programs is sound in that it commutes with reduction. Assuming the Church-Rosser property, erasure furthermore preserves convertibility in general.
We also give an erasure inference algorithm for erasure-unannotated or partially annotated programs and prove it sound, complete, and optimal with respect to the typing rules of the calculus.
Finally, we show that this erasure method is effective in that it can not only recover the expected asymptotic complexity in compiled programs at run time, but it can also shorten compilation times.
Supplemental Material
- Andreas Abel. 2011. Irrelevance in Type Theory with a Heterogeneous Equality Judgement. Springer Berlin Heidelberg, Berlin, Heidelberg, 57-71. https://doi.org/10.1007/978-3-642-19805-2_5 Google Scholar
Cross Ref
- Andreas Abel. 2017. Irrelevance and resurrection in type signatures. Agda Mailing List, 29 July 2017. https://lists.chalmers. se/pipermail/agda/2017/009640.htmlGoogle Scholar
- Andreas Abel, Andrea Vezzosi, and Theo Winterhalter. 2017. Normalization by evaluation for sized dependent types. Proceedings of the ACM on Programming Languages 1, ICFP ( 2017 ), 33. https://doi.org/10.1145/3110277 Google Scholar
Digital Library
- Agda authors. 2020a. Agda 2.6.1 documentation: Irrelevance. https://agda.readthedocs. io/en/v2.6.1/language/irrelevance.html Accessed on 23 May 2020.Google Scholar
- Agda authors. 2020b. Agda 2.6. 1 documentation: Run-time Irrelevance. https://agda.readthedocs. io/en/v2.6.1/language/ runtime-irrelevance. html Accessed on 23 May 2020.Google Scholar
- Danel Ahman, Catalin Hritcu, Guido Martínez, Gordon D. Plotkin, Jonathan Protzenko, Aseem Rastogi, and Nikhil Swamy. 2016. Dijkstra Monads for Free. CoRR abs/1608.06499 ( 2016 ). https://doi.org/10.1145/3093333.3009878 arXiv: 1608. 06499 Google Scholar
Cross Ref
- Robert Atkey. 2018. Syntax and Semantics of Quantitative Type Theory. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2018, Oxford, UK, July 09-12, 2018, Anuj Dawar and Erich Grädel (Eds.). ACM, 56-65. https://doi.org/10.1145/3209108.3209189 Google Scholar
Digital Library
- Bruno Barras and Bruno Bernardo. 2008. The Implicit Calculus of Constructions As a Programming Language with Dependent Types. In Proceedings of the Theory and Practice of Software, 11th International Conference on Foundations of Software Science and Computational Structures (FOSSACS'08/ETAPS'08). Springer-Verlag, Berlin, Heidelberg, 365-379. https://doi.org/10.1007/978-3-540-78499-9_26 Google Scholar
Cross Ref
- Edwin Brady. 2005. Practical Implementation of a Dependently Typed Functional Programming Language. Ph.D. Dissertation. http://eb.host.cs. st-andrews.ac.uk/writings/thesis.pdfGoogle Scholar
- Edwin Brady. 2013. Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of Functional Programming 23, 5 ( 2013 ), 552-593. https://doi.org/10.1017/S095679681300018X Google Scholar
Cross Ref
- Edwin Brady. 2020. Idris 2: Quantitative Type Theory in Action. Submitted. https://www.type-driven.org.uk/edwinb/ papers/idris2.pdfGoogle Scholar
- Edwin Brady, Conor McBride, and James McKinna. 2004. Inductive families need not store their indices. In Types for Proofs and Programs, Torino, 2003, volume 3085 of LNCS. Springer-Verlag, 115-129. https://doi.org/10.1007/978-3-540-24849-1_8 Google Scholar
Cross Ref
- The CHICKEN project. 2020. CHICKEN Scheme. https://www.call-cc.org/. Accessed: 2020-04-25.Google Scholar
- Robert Dockins. 2014. Re: Problem with tactic-generated terms. https://sympa.inria.fr/sympa/arc/coq-club/2014-09/ msg00114.html, accessed on 2015-02-28.Google Scholar
- William F. Dowling and Jean H. Gallier. 1984. Linear-time algorithms for testing the satisfiability of propositional horn formulae. The Journal of Logic Programming 1, 3 ( 1984 ), 267-284. https://doi.org/10.1016/ 0743-1066 ( 84 ) 90014-1 Google Scholar
Cross Ref
- Richard A Eisenberg. 2016. Dependent types in Haskell: Theory and practice. Ph.D. Dissertation. University of Pennsylvania.Google Scholar
- Jean-Christophe Filliâtre and Andrei Paskevich. 2013. Why3-Where Programs Meet Provers. In ESOP'13 22nd European Symposium on Programming (LNCS), Vol. 7792. Springer, Rome, Italy. https://doi.org/10.1007/978-3-642-37036-6_8 Google Scholar
Digital Library
- Michael Gelfond and Vladimir Lifschitz. 1988. The stable model semantics for logic programming.. In ICLP/SLP, Vol. 88. 1070-1080.Google Scholar
- Healfdene Goguen, Conor McBride, and James McKinna. 2006. Eliminating Dependent Pattern Matching. Springer Berlin Heidelberg, Berlin, Heidelberg, 521-540. https://doi.org/10.1007/11780274_27 Google Scholar
Cross Ref
- Adam Gundry. 2013. Type Inference, Haskell and Dependent Types. Ph.D. Dissertation. University of Strathclyde. http://adam.gundry.co.uk/pub/thesis/Google Scholar
- Hugo Herbelin. 2014. Re: Problem with tactic-generated terms. https://sympa.inria.fr/sympa/arc/coq-club/2014-09/msg00118. html, accessed on 2015-02-28.Google Scholar
- Antonius J. C. Hurkens. 1995. A simplification of Girard's paradox. In Typed Lambda Calculi and Applications, Mariangiola Dezani-Ciancaglini and Gordon Plotkin (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 266-278. https://doi.org/ 10.1007/BFb0014058 Google Scholar
Cross Ref
- K Rustan M Leino. 2010. Dafny: An automatic program verifier for functional correctness. In International Conference on Logic for Programming Artificial Intelligence and Reasoning. Springer, 348-370. https://doi.org/10.1007/978-3-642-17511-4_20 Google Scholar
Cross Ref
- K Rustan M Leino and Philipp Rümmer. 2010. A polymorphic intermediate verification language: Design and logical encoding. In International Conference on Tools and Algorithms for the Construction and Analysis of Systems. Springer, 312-327. https://doi.org/10.1007/978-3-642-12002-2_26 Google Scholar
Digital Library
- Jonathan Leivent. 2014a. Mindless Coding. https://github.com/jonleivent/mindless-coding, accessed on 2015-02-28.Google Scholar
- Jonathan Leivent. 2014b. Re: Problem with tactic-generated terms. https://sympa.inria.fr/sympa/arc/coq-club/2014-09/ msg00110.html, accessed on 2015-02-28.Google Scholar
- Pierre Letouzey. 2003. A New Extraction for Coq. In Types for Proofs and Programs, Herman Geuvers and Freek Wiedijk (Eds.). Lecture Notes in Computer Science, Vol. 2646. Springer Berlin Heidelberg, 200-219. https://doi.org/10.1007/3-540-39185-1_12 Google Scholar
Cross Ref
- P. Letouzey. 2004. Programmation fonctionnelle certifiée-L'extraction de programmes dans l'assistant Coq. Ph.D. Dissertation. Université Paris-Sud.Google Scholar
- P. Letouzey. 2008. Extraction in Coq, an Overview. In Logic and Theory of Algorithms, Fourth Conference on Computability in Europe, CiE 2008 (Lecture Notes in Computer Science), A. Beckmann, C. Dimitracopoulos, and B. Löve (Eds.), Vol. 5028. Springer-Verlag. https://doi.org/10.1007/978-3-540-69407-6_39 Google Scholar
Digital Library
- Pierre Letouzey and Bas Spitters. 2005. Implicit and noncomputational arguments using monads.Google Scholar
- Conor McBride. 2000. Dependently typed functional programs and their proofs. Ph.D. Dissertation. University of Edinburgh. College of Science and Engineering. School of Informatics.Google Scholar
- Conor McBride. 2016. I got plenty o'nuttin'. In A List of Successes That Can Change the World. Springer, 207-233. https: //doi.org/10.1007/978-3-319-30936-1_12 Google Scholar
Cross Ref
- Alexandre Miquel. 2001. The Implicit Calculus of Constructions. In TLCA. 344-359. https://doi.org/10.1007/3-540-45413-6_27 Google Scholar
Cross Ref
- Richard Nathan Mishra-Linger. 2008. Irrelevance, Polymorphism, and Erasure in Type Theory. http://citeseerx.ist.psu.edu/ viewdoc/download?doi =10.1.1.154.5619&rep=rep1&type=pdfGoogle Scholar
- Ulf Norell. 2007. Towards a practical programming language based on dependent type theory. Ph.D. Dissertation. Department of Computer Science and Engineering, Chalmers University of Technology, SE-412 96 Göteborg, Sweden.Google Scholar
- Vilhelm Sjöberg. 2015. A Dependently Typed Language with Nontermination. Ph.D. Dissertation. University of Pennsylvania.Google Scholar
- Aaron Stump. 2018. Syntax and Semantics of Cedille. CoRR abs/ 1806.04709 ( 2018 ). arXiv: 1806.04709 http://arxiv.org/abs/ 1806.04709Google Scholar
- Nikhil Swamy, Catalin Hritcu, Chantal Keller, Aseem Rastogi, Antoine Delignat-Lavaud, Simon Forest, Karthikeyan Bhargavan, Cédric Fournet, Pierre-Yves Strub, Markulf Kohlweiss, Jean Karim Zinzindohoue, and Santiago Zanella Béguelin. 2016. Dependent types and multi-monadic efects in F. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, St. Petersburg, FL, USA, January 20-22, 2016, Rastislav Bodík and Rupak Majumdar (Eds.). ACM, 256-270. https://doi.org/10.1145/2837614.2837655 Google Scholar
Digital Library
- The Coq development team. 2004. The Coq proof assistant reference manual. LogiCal Project. http://coq.inria. fr Version 8.0.Google Scholar
- Maarten H Van Emden and Robert A Kowalski. 1976. The semantics of predicate logic as a programming language. Journal of the ACM (JACM) 23, 4 ( 1976 ), 733-742. https://doi.org/10.1145/321978.321991 Google Scholar
Digital Library
- Stephanie Weirich, Antoine Voizard, Pedro Henrique Azevedo de Amorim, and Richard A. Eisenberg. 2017. A Specification for Dependent Types in Haskell. Proc. ACM Program. Lang. 1, ICFP, Article 31 ( Aug. 2017 ), 29 pages. https://doi.org/10. 1145/3110275 Google Scholar
Digital Library
Index Terms
A dependently typed calculus with pattern matching and erasure inference
Recommendations
Dependently typed programming in Agda
TLDI '09: Proceedings of the 4th international workshop on Types in language design and implementationDependently typed languages have for a long time been used to describe proofs about programs. Traditionally, dependent types are used mostly for stating and proving the properties of the programs and not in defining the programs themselves. An ...
Bidirectional Elaboration of Dependently Typed Programs
PPDP '14: Proceedings of the 16th International Symposium on Principles and Practice of Declarative ProgrammingDependently typed programming languages allow programmers to express a rich set of invariants and verify them statically via type checking. To make programming with dependent types practical, dependently typed systems provide a compact language for ...
Propositional equality for gradual dependently typed programming
Gradual dependent types can help with the incremental adoption of dependently typed code by providing a principled semantics for imprecise types and proofs, where some parts have been omitted. Current theories of gradual dependent types, though, lack ...






Comments