Abstract
This paper considers parametricity and its resulting free theorems for nested data types. Rather than representing nested types via their Church encodings in a higher-kinded or dependently typed extension of System F, we adopt a functional programming perspective and design a Hindley-Milner-style calculus with primitives for constructing nested types directly as fixpoints. Our calculus can express all nested types appearing in the literature, including truly nested types. At the term level, it supports primitive pattern matching, map functions, and fold combinators for nested types. Our main contribution is the construction of a parametric model for our calculus. This is both delicate and challenging: to ensure the existence of semantic fixpoints interpreting nested types, and thus to establish a suitable Identity Extension Lemma for our calculus, our type system must explicitly track functoriality of types, and cocontinuity conditions on the functors interpreting them must be appropriately threaded throughout the model construction. We prove that our model satisfies an appropriate Abstraction Theorem and verifies all standard consequences of parametricity for primitive nested types.
Chapter PDF
Similar content being viewed by others
References
Adámek, J., Rosický, J.: Locally Presentable and Accessible Categories. Cambridge University Press (1994)
Atkey, R.: Relational Parametricity for Higher Kinds. In: Computer Science Logic, pp. 46–61. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik (2012)
Bainbridge, E. S., Freyd, P. J., Scedrov, A., Scott, P. J.: Functorial Polymorphism. Theoretical Computer Science 70, 35–64 (1990)
Bird, R., Meertens, L.: Nested datatypes. In: Mathematics of Program Construction, pp. 52–67. Springer (1998)
Bird, R., Paterson, R.: Generalised folds for nested datatypes. Formal Aspects of Computing 11, 200–222 (1999)
Birkedal, L., Møgelberg, R. E.: Categorical models for Abadi and Plotkin’s logic for parametricity. Mathematical Structures in Computer Science 15, 709–772 (2005)
Cardelli, L: Type Systems. In: CRC Handbook of Computer Science and Engineering, pp. 2208–2236. CRC Press (1984)
Dunphy, B., Reddy, U.: Parametric Limits. In: Logic in Computer Science, pp. 242–252. IEEE (2004)
Ghani, N., Johann, P., Nordvall Forsberg, F., Orsanigo, F., Revell, T.: Bifibrational Functorial Semantics for Parametric Polymorphism. Electronic Notes in Theoretical Computer Science 319, 165–181. (2015)
Gill, A., Launchbury, J., Peyton Jones, S. L.: A short cut to deforestation. In: Functional Programming Languages and Computer Architecture, Proceedings, pp. 223–232. Association for Computing Machinery (1993)
Girard, J.-Y.: Interprétation fonctionnelle et élimination des coupures de l’arithmétique d’ordre supérieur. PhD thesis, University of Paris (1972)
Hasegawa, R.: Categorical data types in parametric polymorphism. Mathematical Structures in Computer Science 4, 71–109 (1994)
Jacobs, B.: Categorical Logic and Type Theory. Elsevier (1999)
Johann, P.: A Generalization of Short-Cut Fusion and Its Correctness Proof. Higher-Order and Symbolic Computation 15, 273–300 (2002)
Johann, P., Ghani, N.: Foundations for Structured Programming with GADTs. In: Principles of Programming Languages, pp. 297–308. Association for Computing Machinery (2008)
Johann, P., Ghani, N.: Haskell Programming with Nested Types: A Principled Approach Higher-Order and Symbolic Computation 22(2), 155–189 (2010)
Johann, P., Polonsky, A.: Higher-kinded data types: Syntax and Semantics. In: Logic in Computer Science, pp. 1–13. IEEE (2019)
Johann, P., Polonsky, A.: Deep Induction: Induction Rules for (Truly) Nested Types. In: Foundations of Software Science and Computation Structures, pp. 339–358. Springer (2020)
Matthes, R.: Map Fusion for Nested Datatypes in Intensional Type Theory. Science of Computer Programming 76(3), 204–224 (2011)
Ma, Q., Reynolds, J. C.: Types, abstraction, and parametric polymorphism, part 2. In: Mathematical Foundations of Program Semantics, pp. 1–40. Springer-Verlag (1992)
Martin, C., Gibbons, J.: On the semantics of nested datatypes. Information Processing Letters 80(5), 233–238 (2001)
Pitts, A.: Parametric polymorphism, recursive types, and operational equivalence. (1998)
Pitts, A.: Parametric polymorphism and operational equivalence. Mathematical Structures in Computer Science 10, 321–359 (2000)
Reynolds, J. C.: Types, abstraction, and parametric polymorphism. Information Processing 83(1), 513–523 (1983)
Reynolds, J. C.: Polymorphism is not set-theoretic. Semantics of Data Types, 145–156 (1984)
Robinson, E., Rosolini, G.: Reflexive graphs and parametric polymorphism. In: Logic in Computer Science, pp. 364–371. IEEE (1994)
Wadler, P.: Theorems for free!. In: Functional Programming Languages and Computer Architecture, Proceedings, pp. 347–359. Association for Computing Machinery (1989)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.
The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.
Copyright information
© 2021 The Author(s)
About this paper
Cite this paper
Johann, P., Ghiorzi, E., Jeffries, D. (2021). Parametricity for Primitive Nested Types. In: Kiefer, S., Tasson, C. (eds) Foundations of Software Science and Computation Structures. FOSSACS 2021. Lecture Notes in Computer Science(), vol 12650. Springer, Cham. https://doi.org/10.1007/978-3-030-71995-1_17
Download citation
DOI: https://doi.org/10.1007/978-3-030-71995-1_17
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-71994-4
Online ISBN: 978-3-030-71995-1
eBook Packages: Computer ScienceComputer Science (R0)