skip to main content
research-article
Open Access

A dependently typed calculus with pattern matching and erasure inference

Published:03 August 2020Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

Presentation at ICFP '20

References

  1. 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 ScholarGoogle ScholarCross RefCross Ref
  2. Andreas Abel. 2017. Irrelevance and resurrection in type signatures. Agda Mailing List, 29 July 2017. https://lists.chalmers. se/pipermail/agda/2017/009640.htmlGoogle ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle Scholar
  5. 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 ScholarGoogle Scholar
  6. 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 ScholarGoogle ScholarCross RefCross Ref
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarCross RefCross Ref
  9. 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 ScholarGoogle Scholar
  10. 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 ScholarGoogle ScholarCross RefCross Ref
  11. Edwin Brady. 2020. Idris 2: Quantitative Type Theory in Action. Submitted. https://www.type-driven.org.uk/edwinb/ papers/idris2.pdfGoogle ScholarGoogle Scholar
  12. 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 ScholarGoogle ScholarCross RefCross Ref
  13. The CHICKEN project. 2020. CHICKEN Scheme. https://www.call-cc.org/. Accessed: 2020-04-25.Google ScholarGoogle Scholar
  14. 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 ScholarGoogle Scholar
  15. 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 ScholarGoogle ScholarCross RefCross Ref
  16. Richard A Eisenberg. 2016. Dependent types in Haskell: Theory and practice. Ph.D. Dissertation. University of Pennsylvania.Google ScholarGoogle Scholar
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. Michael Gelfond and Vladimir Lifschitz. 1988. The stable model semantics for logic programming.. In ICLP/SLP, Vol. 88. 1070-1080.Google ScholarGoogle Scholar
  19. 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 ScholarGoogle ScholarCross RefCross Ref
  20. Adam Gundry. 2013. Type Inference, Haskell and Dependent Types. Ph.D. Dissertation. University of Strathclyde. http://adam.gundry.co.uk/pub/thesis/Google ScholarGoogle Scholar
  21. 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 ScholarGoogle Scholar
  22. 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 ScholarGoogle ScholarCross RefCross Ref
  23. 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 ScholarGoogle ScholarCross RefCross Ref
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. Jonathan Leivent. 2014a. Mindless Coding. https://github.com/jonleivent/mindless-coding, accessed on 2015-02-28.Google ScholarGoogle Scholar
  26. 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 ScholarGoogle Scholar
  27. 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 ScholarGoogle ScholarCross RefCross Ref
  28. P. Letouzey. 2004. Programmation fonctionnelle certifiée-L'extraction de programmes dans l'assistant Coq. Ph.D. Dissertation. Université Paris-Sud.Google ScholarGoogle Scholar
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. Pierre Letouzey and Bas Spitters. 2005. Implicit and noncomputational arguments using monads.Google ScholarGoogle Scholar
  31. 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 ScholarGoogle Scholar
  32. 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 ScholarGoogle ScholarCross RefCross Ref
  33. Alexandre Miquel. 2001. The Implicit Calculus of Constructions. In TLCA. 344-359. https://doi.org/10.1007/3-540-45413-6_27 Google ScholarGoogle ScholarCross RefCross Ref
  34. 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 ScholarGoogle Scholar
  35. 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 ScholarGoogle Scholar
  36. Vilhelm Sjöberg. 2015. A Dependently Typed Language with Nontermination. Ph.D. Dissertation. University of Pennsylvania.Google ScholarGoogle Scholar
  37. Aaron Stump. 2018. Syntax and Semantics of Cedille. CoRR abs/ 1806.04709 ( 2018 ). arXiv: 1806.04709 http://arxiv.org/abs/ 1806.04709Google ScholarGoogle Scholar
  38. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  39. The Coq development team. 2004. The Coq proof assistant reference manual. LogiCal Project. http://coq.inria. fr Version 8.0.Google ScholarGoogle Scholar
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A dependently typed calculus with pattern matching and erasure inference

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            • Published in

              cover image Proceedings of the ACM on Programming Languages
              Proceedings of the ACM on Programming Languages  Volume 4, Issue ICFP
              August 2020
              1070 pages
              EISSN:2475-1421
              DOI:10.1145/3415018
              Issue’s Table of Contents

              Copyright © 2020 Owner/Author

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 3 August 2020
              Published in pacmpl Volume 4, Issue ICFP

              Permissions

              Request permissions about this article.

              Request Permissions

              Check for updates

              Qualifiers

              • research-article

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader
            About Cookies On This Site

            We use cookies to ensure that we give you the best experience on our website.

            Learn more

            Got it!