skip to main content
research-article
Open access

A Graded Modal Dependent Type Theory with a Universe and Erasure, Formalized

Published: 31 August 2023 Publication History

Abstract

We present a graded modal type theory, a dependent type theory with grades that can be used to enforce various properties of the code. The theory has Π-types, weak and strong Σ-types, natural numbers, an empty type, and a universe, and we also extend the theory with a unit type and graded Σ-types. The theory is parameterized by a modality, a kind of partially ordered semiring, whose elements (grades) are used to track the usage of variables in terms and types. Different modalities are possible. We focus mainly on quantitative properties, in particular erasure: with the erasure modality one can mark function arguments as erasable.
The theory is fully formalized in Agda. The formalization, which uses a syntactic Kripke logical relation at its core and is based on earlier work, establishes major meta-theoretic properties such as subject reduction, consistency, normalization, and decidability of definitional equality. We also prove a substitution theorem for grade assignment, and preservation of grades under reduction. Furthermore we study an extraction function that translates terms to an untyped λ-calculus and removes erasable content, in particular function arguments with the “erasable” grade. For a certain class of modalities we prove that extraction is sound, in the sense that programs of natural number type have the same value before and after extraction. Soundness of extraction holds also for open programs, as long as all variables in the context are erasable, the context is consistent, and erased matches are not allowed for weak Σ-types.

References

[1]
Andreas Abel. 2006. Polarized Subtyping for Sized Types. In Computer Science – Theory and Applications, First International Computer Science Symposium in Russia, CSR 2006 (LNCS, Vol. 3967). 381–392. https://doi.org/10.1007/11753728_39
[2]
Andreas Abel. 2018. Resourceful Dependent Types. In 24th International Conference on Types for Proofs and Programs, TYPES 2018, Abstracts. 7–8. https://types2018.projj.eu/book-of-abstracts/
[3]
Andreas Abel and Jean-Philippe Bernardy. 2020. A Unified View of Modalities in Type Systems. Proc. ACM Program. Lang., 4, ICFP (2020), Article 90, Aug., 28 pages. https://doi.org/10.1145/3408972
[4]
Andreas Abel, Thierry Coquand, and Bassel Mannaa. 2016. On the Decidability of Conversion in Type Theory. In TYPES 2016, Types for Proofs and Programs, 22nd Meeting, Book of Abstracts. 5–6. http://www.types2016.uns.ac.rs/images/abstracts/abel1.pdf
[5]
Andreas Abel, Nils Anders Danielsson, and Oskar Eriksson. 2023. An Agda Formalization of a Graded Modal Type Theory with a Universe and Erasure. https://doi.org/10.5281/zenodo.8119348
[6]
Andreas Abel, Nils Anders Danielsson, and Andrea Vezzosi. 2021. Compiling Programs with Erased Univalence. Draft. https://www.cse.chalmers.se/~nad/publications/abel-danielsson-vezzosi-erased-univalence.html
[7]
Andreas Abel, Joakim Öhman, and Andrea Vezzosi. 2017. Decidability of Conversion for Type Theory in Type Theory. Proc. ACM Program. Lang., 2, POPL (2017), Article 23, Dec., 29 pages. https://doi.org/10.1145/3158111
[8]
Andreas Abel and Gabriel Scherer. 2012. On Irrelevance and Algorithmic Equality in Predicative Type Theory. Logical Methods in Computer Science, 8, 1 (2012), March, 36 pages. https://doi.org/10.2168/LMCS-8(1:29)2012
[9]
Robert Atkey. 2018. Syntax and Semantics of Quantitative Type Theory. In LICS ’18: Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science. 56–65. https://doi.org/10.1145/3209108.3209189
[10]
Jean-Philippe Bernardy, Mathieu Boespflug, Ryan R. Newton, Simon Peyton Jones, and Arnaud Spiwack. 2017. Linear Haskell: Practical Linearity in a Higher-Order Polymorphic Language. Proc. ACM Program. Lang., 2, POPL (2017), Article 5, Dec., 29 pages. https://doi.org/10.1145/3158093
[11]
Edwin Brady. 2021. Idris 2: Quantitative Type Theory in Practice. In 35th European Conference on Object-Oriented Programming, ECOOP 2021 (LIPIcs, Vol. 194). 26 pages. https://doi.org/10.4230/LIPIcs.ECOOP.2021.9
[12]
Aloïs Brunel, Marco Gaboardi, Damiano Mazza, and Steve Zdancewic. 2014. A Core Quantitative Coeffect Calculus. In Programming Languages and Systems, 23rd European Symposium on Programming, ESOP 2014 (LNCS, Vol. 8410). 351–370. https://doi.org/10.1007/978-3-642-54833-8_19
[13]
Pritam Choudhury, Harley Eades III, Richard A. Eisenberg, and Stephanie Weirich. 2021. A Graded Dependent Type System with a Usage-Aware Semantics. Proc. ACM Program. Lang., 5, POPL (2021), Article 50, Jan., 32 pages. https://doi.org/10.1145/3434331
[14]
Pritam Choudhury, Harley Eades III, and Stephanie Weirich. 2022. A Dependent Dependency Calculus. In Programming Languages and Systems, 31st European Symposium on Programming, ESOP 2022 (LNCS, Vol. 13240). 403–430. https://doi.org/10.1007/978-3-030-99336-8_15
[15]
Cyril Cohen, Thierry Coquand, Simon Huber, and Anders Mörtberg. 2015. Cubical Type Theory: A Constructive Interpretation of the Univalence Axiom. In 21st International Conference on Types for Proofs and Programs, TYPES 2015 (LIPIcs, Vol. 69). 34 pages. https://doi.org/10.4230/LIPIcs.TYPES.2015.5
[16]
Karl Crary, Stephanie Weirich, and Greg Morrisett. 2002. Intensional polymorphism in type-erasure semantics. Journal of Functional Programming, 12, 6 (2002), Nov., 567–600. https://doi.org/10.1017/S0956796801004282
[17]
Peng Fu, Kohei Kishida, and Peter Selinger. 2022. Linear Dependent Type Theory for Quantum Programming Languages. Logical Methods in Computer Science, 18, 3 (2022), Sept., 44 pages. https://doi.org/10.46298/lmcs-18(3:28)2022
[18]
Herman Geuvers. 1994. A short and flexible proof of Strong Normalization for the Calculus of Constructions. In Types for Proofs and Programs, International Workshop TYPES ’94 (LNCS, Vol. 996). 14–38. https://doi.org/10.1007/3-540-60579-7_2
[19]
Dan R. Ghica and Alex I. Smith. 2014. Bounded Linear Types in a Resource Semiring. In Programming Languages and Systems, 23rd European Symposium on Programming, ESOP 2014 (LNCS, Vol. 8410). 331–350. https://doi.org/10.1007/978-3-642-54833-8_18
[20]
Daniel Gratzer, G.A. Kavvos, Andreas Nuyts, and Lars Birkedal. 2021. Multimodal Dependent Type Theory. Logical Methods in Computer Science, 17, 3 (2021), July, 67 pages. https://doi.org/10.46298/lmcs-17(3:11)2021
[21]
Pierre Letouzey. 2003. A New Extraction for Coq. In Types for Proofs and Programs, International Workshop, TYPES 2002 (LNCS, Vol. 2646). 200–219. https://doi.org/10.1007/3-540-39185-1_12
[22]
Conor McBride. 2016. I Got Plenty o’ Nuttin’. In A List of Successes That Can Change the World (LNCS, Vol. 9600). 207–233. https://doi.org/10.1007/978-3-319-30936-1_12
[23]
Nathan Mishra-Linger and Tim Sheard. 2008. Erasure and Polymorphism in Pure Type Systems. In Foundations of Software Science and Computational Structures, 11th International Conference, FOSSACS 2008 (LNCS, Vol. 4962). 350–364. https://doi.org/10.1007/978-3-540-78499-9_25
[24]
Benjamin Moon, Harley Eades III, and Dominic Orchard. 2021. Graded Modal Dependent Type Theory. In Programming Languages and Systems, 30th European Symposium on Programming, ESOP 2021 (LNCS, Vol. 12648). 462–490. https://doi.org/10.1007/978-3-030-72019-3_17
[25]
Dominic Orchard, Vilem-Benjamin Liepelt, and Harley Eades III. 2019. Quantitative Program Reasoning with Graded Modal Types. Proc. ACM Program. Lang., 3, ICFP (2019), Article 110, July, 30 pages. https://doi.org/10.1145/3341714
[26]
Tomas Petricek, Dominic Orchard, and Alan Mycroft. 2014. Coeffects: A Calculus of Context-Dependent Computation. In ICFP’14, Proceedings of the 2014 ACM SIGPLAN International Conference on Functional programming. 123–135. https://doi.org/10.1145/2628136.2628160
[27]
Frank Pfenning. 2001. Intensionality, Extensionality, and Proof Irrelevance in Modal Type Theory. In Proceedings, 16th Annual IEEE Symposium on Logic in Computer Science. 221–230. https://doi.org/10.1109/LICS.2001.932499
[28]
Jason Reed and Benjamin C. Pierce. 2010. Distance Makes the Types Grow Stronger: A Calculus for Differential Privacy. In ICFP’10, Proceedings of the 2010 ACM SIGPLAN International Conference on Functional programming. 157–168. https://doi.org/10.1145/1863543.1863568
[29]
Egbert Rijke, Michael Shulman, and Bas Spitters. 2020. Modalities in homotopy type theory. Logical Methods in Computer Science, 16, 1 (2020), Jan., 79 pages. https://doi.org/10.23638/LMCS-16(1:2)2020
[30]
Martin Steffen. 1998. Polarized Higher-Order Subtyping. Ph. D. Dissertation. Universität Erlangen-Nürnberg.
[31]
Sandro Stucki and Paolo G. Giarrusso. 2021. A Theory of Higher-Order Subtyping with Type Intervals. Proc. ACM Program. Lang., 5, ICFP (2021), Article 69, Aug., 30 pages. https://doi.org/10.1145/3473574
[32]
Matúš Tejiščák. 2020. A Dependently Typed Calculus with Pattern Matching and Erasure Inference. Proc. ACM Program. Lang., 4, ICFP (2020), Article 91, Aug., 29 pages. https://doi.org/10.1145/3408973
[33]
The Agda Team. 2023. Agda User Manual, Release 2.6.3. https://readthedocs.org/projects/agda/downloads/pdf/v2.6.3/
[34]
The Coq Development Team. 2023. The Coq Reference Manual, Release 8.17.1. https://github.com/coq/coq/releases/download/V8.17.1/coq-8.17.1-reference-manual.pdf
[35]
The Univalent Foundations Program. 2013. Homotopy Type Theory: Univalent Foundations of Mathematics (first ed.). https://homotopytypetheory.org/book/
[36]
Dennis Volpano, Cynthia Irvine, and Geoffrey Smith. 1996. A sound type system for secure flow analysis. Journal of Computer Security, 4, 2–3 (1996), April, 167–187. https://doi.org/10.3233/JCS-1996-42-304
[37]
James Wood and Robert Atkey. 2021. A Linear Algebra Approach to Linear Metatheory. In Proceedings Second Joint International Workshop on Linearity & Trends in Linear Logic and Applications (EPTCS, Vol. 353). 195–212. https://doi.org/10.4204/EPTCS.353.10

Cited By

View all
  • (2024)Effects and Coeffects in Call-by-Push-ValueProceedings of the ACM on Programming Languages10.1145/36897508:OOPSLA2(1108-1134)Online publication date: 8-Oct-2024
  • (2024)Functional Ownership through Fractional UniquenessProceedings of the ACM on Programming Languages10.1145/36498488:OOPSLA1(1040-1070)Online publication date: 29-Apr-2024
  • (2024)Polynomial Time and Dependent TypesProceedings of the ACM on Programming Languages10.1145/36329188:POPL(2288-2317)Online publication date: 5-Jan-2024

Index Terms

  1. A Graded Modal Dependent Type Theory with a Universe and Erasure, Formalized
    Index terms have been assigned to the content through auto-classification.

    Recommendations

    Comments

    Please enable JavaScript to view thecomments powered by Disqus.

    Information & Contributors

    Information

    Published In

    cover image Proceedings of the ACM on Programming Languages
    Proceedings of the ACM on Programming Languages  Volume 7, Issue ICFP
    August 2023
    981 pages
    EISSN:2475-1421
    DOI:10.1145/3554311
    Issue’s Table of Contents
    This work is licensed under a Creative Commons Attribution 4.0 International License.

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 31 August 2023
    Published in PACMPL Volume 7, Issue ICFP

    Permissions

    Request permissions for this article.

    Check for updates

    Badges

    Author Tags

    1. dependent types
    2. erasure
    3. formalization
    4. graded modal type theory
    5. linearity
    6. modalities

    Qualifiers

    • Research-article

    Funding Sources

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)373
    • Downloads (Last 6 weeks)44
    Reflects downloads up to 10 Nov 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2024)Effects and Coeffects in Call-by-Push-ValueProceedings of the ACM on Programming Languages10.1145/36897508:OOPSLA2(1108-1134)Online publication date: 8-Oct-2024
    • (2024)Functional Ownership through Fractional UniquenessProceedings of the ACM on Programming Languages10.1145/36498488:OOPSLA1(1040-1070)Online publication date: 29-Apr-2024
    • (2024)Polynomial Time and Dependent TypesProceedings of the ACM on Programming Languages10.1145/36329188:POPL(2288-2317)Online publication date: 5-Jan-2024

    View Options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Get Access

    Login options

    Full Access

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media