Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

The Essence of Generalized Algebraic Data Types

Published: 05 January 2024 Publication History

Abstract

This paper considers direct encodings of generalized algebraic data types (GADTs) in a minimal suitable lambda-calculus. To this end, we develop an extension of System Fω with recursive types and internalized type equalities with injective constant type constructors. We show how GADTs and associated pattern-matching constructs can be directly expressed in the calculus, thus showing that it may be treated as a highly idealized modern functional programming language. We prove that the internalized type equalities in conjunction with injectivity rules increase the expressive power of the calculus by establishing a non-macro-expressibility result in Fω, and prove the system type-sound via a syntactic argument. Finally, we build two relational models of our calculus: a simple, unary model that illustrates a novel, two-stage interpretation technique, necessary to account for the equational constraints; and a more sophisticated, binary model that relaxes the construction to allow, for the first time, formal reasoning about data-abstraction in a calculus equipped with GADTs.

References

[1]
Guillaume Allais, James Chapman, Conor McBride, and James McKinna. 2017. Type-and-scope safe programs and their proofs. In Proceedings of the 6th ACM SIGPLAN Conference on Certified Programs and Proofs, CPP 2017, Paris, France, January 16-17, 2017, Yves Bertot and Viktor Vafeiadis (Eds.). ACM, 195–207. https://doi.org/10.1145/3018610.3018613
[2]
Robert Atkey. 2012. Relational Parametricity for Higher Kinds. In Computer Science Logic (CSL’12) - 26th International Workshop/21st Annual Conference of the EACSL, CSL 2012, September 3-6, 2012, Fontainebleau, France, Patrick Cégielski and Arnaud Durand (Eds.) (LIPIcs, Vol. 16). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 46–61. https://doi.org/10.4230/LIPIcs.CSL.2012.46
[3]
H. P. Barendregt. 1993. Lambda Calculi with Types. Oxford University Press, Inc., USA. 117–309. isbn:0198537611
[4]
Ulrich Berger and Helmut Schwichtenberg. 1991. An Inverse of the Evaluation Functional for Typed lambda-calculus. In Proceedings of the Sixth Annual Symposium on Logic in Computer Science (LICS ’91), Amsterdam, The Netherlands, July 15-18, 1991. IEEE Computer Society, 203–211. https://doi.org/10.1109/LICS.1991.151645
[5]
Richard S. Bird and Lambert G. L. T. Meertens. 1998. Nested Datatypes. In Mathematics of Program Construction, MPC’98, Marstrand, Sweden, June 15-17, 1998, Proceedings, Johan Jeuring (Ed.) (Lecture Notes in Computer Science, Vol. 1422). Springer, 52–67. https://doi.org/10.1007/BFb0054285
[6]
James Cheney and Ralf Hinze. 2003. First-Class Phantom Types.
[7]
Olivier Danvy. 1996. Type-Directed Partial Evaluation. In Conference Record of POPL’96: The 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Papers Presented at the Symposium, St. Petersburg Beach, Florida, USA, January 21-24, 1996, Hans-Juergen Boehm and Guy L. Steele Jr. (Eds.). ACM Press, 242–257. https://doi.org/10.1145/237721.237784
[8]
Derek Dreyer, Amal Ahmed, and Lars Birkedal. 2011. Logical Step-Indexed Logical Relations. Log. Methods Comput. Sci., 7, 2 (2011), https://doi.org/10.2168/LMCS-7(2:16)2011
[9]
Jana Dunfield and Neelakantan R. Krishnaswami. 2019. Sound and Complete Bidirectional Typechecking for Higher-Rank Polymorphism with Existentials and Indexed Types. Proc. ACM Program. Lang., 3, POPL (2019), Article 9, jan, 28 pages. https://doi.org/10.1145/3290322
[10]
Matthias Felleisen. 1991. On the Expressive Power of Programming Languages. Sci. Comput. Program., 17, 1-3 (1991), 35–75. https://doi.org/10.1016/0167-6423(91)90036-W
[11]
Marcelo P. Fiore. 2002. Semantic analysis of normalisation by evaluation for typed lambda calculus. In Proceedings of the 4th international ACM SIGPLAN conference on Principles and practice of declarative programming, October 6-8, 2002, Pittsburgh, PA, USA (Affiliated with PLI 2002). ACM, 26–37. https://doi.org/10.1145/571157.571161
[12]
Marcelo P. Fiore, Gordon D. Plotkin, and Daniele Turi. 1999. Abstract Syntax and Variable Binding. In 14th Annual IEEE Symposium on Logic in Computer Science, Trento, Italy, July 2-5, 1999. IEEE Computer Society, 193–202. https://doi.org/10.1109/LICS.1999.782615
[13]
Jean-Yves Girard. 1992. A Fixpoint Theorem in Linear Logic. Post to Linear Logic mailing list, http://www.seas.upenn.edu/ sweirich/types/archive/1992/msg00030.html
[14]
Ryu Hasegawa. 1994. Categorical Data Types in Parametric Polymorphism. Math. Struct. Comput. Sci., 4, 1 (1994), 71–109. https://doi.org/10.1017/S0960129500000372
[15]
Patricia Johann and Pierre Cagne. 2022. How Functorial Are (Deep) GADTs? CoRR, abs/2203.14891 (2022), https://doi.org/10.48550/arXiv.2203.14891 arXiv:2203.14891.
[16]
Patricia Johann and Neil Ghani. 2008. Foundations for structured programming with GADTs. In Proceedings of the 35th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2008, San Francisco, California, USA, January 7-12, 2008, George C. Necula and Philip Wadler (Eds.). ACM, 297–308. https://doi.org/10.1145/1328438.1328475
[17]
Patricia Johann and Enrico Ghiorzi. 2021. Parametricity for Nested Types and GADTs. Log. Methods Comput. Sci., 17, 4 (2021), https://doi.org/10.46298/lmcs-17(4:23)2021
[18]
Patricia Johann and Enrico Ghiorzi. 2022. (Deep) induction rules for GADTs. In CPP ’22: 11th ACM SIGPLAN International Conference on Certified Programs and Proofs, Philadelphia, PA, USA, January 17 - 18, 2022, Andrei Popescu and Steve Zdancewic (Eds.). ACM, 324–337. https://doi.org/10.1145/3497775.3503680
[19]
Patricia Johann, Enrico Ghiorzi, and Daniel Jeffries. 2021. GADTs, Functoriality, Parametricity: Pick Two. In Proceedings 16th Logical and Semantic Frameworks with Applications, LSFA 2021, Buenos Aires, Argentina (Online), 23rd - 24th July, 2021, Mauricio Ayala-Rincón and Eduardo Bonelli (Eds.) (EPTCS, Vol. 357). 77–92. https://doi.org/10.4204/EPTCS.357.6
[20]
Simon L. Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Geoffrey Washburn. 2006. Simple unification-based type inference for GADTs. In Proceedings of the 11th ACM SIGPLAN International Conference on Functional Programming, ICFP 2006, Portland, Oregon, USA, September 16-21, 2006, John H. Reppy and Julia Lawall (Eds.). ACM, 50–61. https://doi.org/10.1145/1159803.1159811
[21]
Ralf Jung, Robbert Krebbers, Jacques-Henri Jourdan, Ales Bizjak, Lars Birkedal, and Derek Dreyer. 2018. Iris from the ground up: A modular foundation for higher-order concurrent separation logic. J. Funct. Program., 28 (2018), e20. https://doi.org/10.1017/S0956796818000151
[22]
Paul Blain Levy, John Power, and Hayo Thielecke. 2003. Modelling environments in call-by-value programming languages. Inf. Comput., 185, 2 (2003), 182–210. https://doi.org/10.1016/S0890-5401(03)00088-9
[23]
Saunders Mac Lane and Ieke Moerdijk. 1992. Sheaves in geometry and logic: a first introduction to topos theory. Springer. isbn:0-387-97710-4
[24]
Christine Paulin-Mohring. 1993. Inductive Definitions in the system Coq - Rules and Properties. In Typed Lambda Calculi and Applications, International Conference on Typed Lambda Calculi and Applications, TLCA ’93, Utrecht, The Netherlands, March 16-18, 1993, Proceedings, Marc Bezem and Jan Friso Groote (Eds.) (Lecture Notes in Computer Science, Vol. 664). Springer, 328–345. https://doi.org/10.1007/BFb0037116
[25]
Benjamin C. Pierce. 2002. Types and programming languages. MIT Press. isbn:978-0-262-16209-8
[26]
Piotr Polesiuk. 2017. IxFree: Step-indexed logical relations in Coq. In 3 rd International Workshop on Coq for Programming Languages (CoqPL).
[27]
François Pottier and Yann Régis-Gianas. 2006. Stratified type inference for generalized algebraic data types. In Proceedings of the 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2006, Charleston, South Carolina, USA, January 11-13, 2006, J. Gregory Morrisett and Simon L. Peyton Jones (Eds.). ACM, 232–244. https://doi.org/10.1145/1111037.1111058
[28]
Edmund P. Robinson and Giuseppe Rosolini. 1994. Reflexive Graphs and Parametric Polymorphism. In Proceedings of the Ninth Annual Symposium on Logic in Computer Science (LICS ’94), Paris, France, July 4-7, 1994. IEEE Computer Society, 364–371. https://doi.org/10.1109/LICS.1994.316053
[29]
Peter Schroeder-Heister. 1994. Definitional reflection and the completion. In Extensions of Logic Programming, Roy Dyckhoff (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 333–347. isbn:978-3-540-48417-2
[30]
Tim Sheard and Emir Pasalic. 2008. Meta-programming With Built-in Type Equality. Electron. Notes Theor. Comput. Sci., 199 (2008), 49–65. https://doi.org/10.1016/j.entcs.2007.11.012
[31]
Filip Sieczkowski, Sergei Stepanenko, Jonathan Sterling, and Lars Birkedal. 2023. The Essence of Generalized Algebraic Data Types. https://doi.org/10.5281/zenodo.10040534
[32]
Jonathan Sterling and Robert Harper. 2018. Guarded Computational Type Theory. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science (LICS ’18). ACM, New York, NY, USA. 879–888. isbn:978-1-4503-5583-4 https://doi.org/10.1145/3209108.3209153
[33]
Martin Sulzmann, Manuel M. T. Chakravarty, Simon L. Peyton Jones, and Kevin Donnelly. 2007. System F with type equality coercions. In Proceedings of TLDI’07: 2007 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation, Nice, France, January 16, 2007, François Pottier and George C. Necula (Eds.). ACM, 53–66. https://doi.org/10.1145/1190315.1190324
[34]
Dimitrios Vytiniotis and Stephanie Weirich. 2010. Parametricity, type equality, and higher-order polymorphism. J. Funct. Program., 20, 2 (2010), 175–210. https://doi.org/10.1017/S0956796810000079
[35]
Philip Wadler. 1989. Theorems for Free!. In Proceedings of the fourth international conference on Functional programming languages and computer architecture, FPCA 1989, London, UK, September 11-13, 1989, Joseph E. Stoy (Ed.). ACM, 347–359. https://doi.org/10.1145/99370.99404
[36]
Stephanie Weirich, Justin Hsu, and Richard A. Eisenberg. 2013. System FC with explicit kind equality. In ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Boston, MA, USA - September 25 - 27, 2013, Greg Morrisett and Tarmo Uustalu (Eds.). ACM, 275–286. https://doi.org/10.1145/2500365.2500599
[37]
Andrew K. Wright and Matthias Felleisen. 1994. A Syntactic Approach to Type Soundness. Inf. Comput., 115, 1 (1994), 38–94. https://doi.org/10.1006/inco.1994.1093
[38]
Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded recursive datatype constructors. In Conference Record of POPL 2003: The 30th SIGPLAN-SIGACT Symposium on Principles of Programming Languages, New Orleans, Louisisana, USA, January 15-17, 2003, Alex Aiken and Greg Morrisett (Eds.). ACM, 224–235. https://doi.org/10.1145/604131.604150

Cited By

View all
  • (2024)The Essence of the Flyweight Design PatternProceedings of the Workshop Dedicated to Jens Palsberg on the Occasion of His 60th Birthday10.1145/3694848.3694855(30-38)Online publication date: 22-Oct-2024
  • (2024)Fulfilling OCaml Modules with TransparencyProceedings of the ACM on Programming Languages10.1145/36498188:OOPSLA1(194-222)Online publication date: 29-Apr-2024

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 8, Issue POPL
January 2024
2820 pages
EISSN:2475-1421
DOI:10.1145/3554315
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: 05 January 2024
Published in PACMPL Volume 8, Issue POPL

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. Generalized Algebraic Data Types
  2. Logical Relations

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)1,130
  • Downloads (Last 6 weeks)81
Reflects downloads up to 28 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2024)The Essence of the Flyweight Design PatternProceedings of the Workshop Dedicated to Jens Palsberg on the Occasion of His 60th Birthday10.1145/3694848.3694855(30-38)Online publication date: 22-Oct-2024
  • (2024)Fulfilling OCaml Modules with TransparencyProceedings of the ACM on Programming Languages10.1145/36498188:OOPSLA1(194-222)Online publication date: 29-Apr-2024

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media