Abstract
Parametricity is one of the foundational principles which underpin our understanding of modern programming languages. Roughly speaking, parametricity expresses the hidden invariants that programs satisfy by formalising the intuition that programs map related inputs to related outputs. Traditionally parametricity is formulated with proof-irrelevant relations but programming in Type Theory requires an extension to proof-relevant relations. But then one might ask: can our proofs that polymorphic functions are parametric be parametric themselves? This paper shows how this can be done and, excitingly, our answer requires a trip into the world of higher dimensional parametricity.
This work is partially supported by SICSA, and EPSRC grants EP/K023837/1 and EP/M016951/1.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
In Coq, this feature can be turned on by means of the command line option -impredicative-set.
References
Atkey, R.: Relational parametricity for higher kinds. In: Cégielski, P., Durand, A. (eds.) CSL 2012. LIPIcs, vol. 16, pp. 46–61. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, Dagstuhl (2012)
Atkey, R., Ghani, N., Johann, P.: A relationally parametric model of dependent type theory. In: POPL, pp. 503–515. ACM (2014)
Bernardy, J.P., Coquand, T., Moulin, G.: A presheaf model of parametric type theory. In: Ghica, D.R. (ed.) MFPS, pp. 17–33. ENTCS, Elsevier, Amsterdam (2015)
Bernardy, J.P., Jansson, P., Paterson, R.: Proofs for free. J. Funct. Program. 22, 107–152 (2012)
Bezem, M., Coquand, T., Huber, S.: A model of type theory in cubical sets. In: Types for Proofs and Programs (TYPES 2013). Leibniz International Proceedings in Informatics, vol. 26, pp. 107–128. Schloss Dagstuhl-Leibniz-Zentrum für Informatik (2014)
Brown, R., Higgins, P.J.: On the algebra of cubes. J. Pure Appl. Algebra 21(3), 233–260 (1981)
Brown, R., Higgins, P.J., Sivera, R.: Nonabelian Algebraic Topology: Filtered Spaces, Crossed Complexes, Cubical Homotopy Groupoids. EMS Tracts in Mathematics, vol. 15. European Mathematical Society Publishing House, Zurich (2011)
Coquand, T., Huet, G.: The calculus of constructions. Inf. Comput. 76, 95–120 (1988)
Dunphy, B., Reddy, U.: Parametric limits. In: LICS, pp. 242–251 (2004)
Garner, R.: Two-dimensional models of type theory. Math. Struct. Comput. Sci. 19(04), 687–736 (2009)
Ghani, N., Johann, P., Nordvall Forsberg, F., Orsanigo, F., Revell, T.: Bifibrational functorial semantics of parametric polymorphism. In: Ghica, D.R. (ed.) MFPS, pp. 67–83. ENTCS, Elsevier, Amsterdam (2015a)
Ghani, N., Nordvall Forsberg, F., Orsanigo, F.: Parametric polymorphism — universally. In: de Paiva, V., de Queiroz, R., Moss, L.S., Leivant, D., de Oliveira, A. (eds.) WoLLIC 2015. LNCS, vol. 9160, pp. 81–92. Springer, Heidelberg (2015b)
Grandis, M.: The role of symmetries in cubical sets and cubical categories (on weak cubical categories, I). Cah. Topol. Gom. Diff. Catg. 50(2), 102–143 (2009)
Krishnaswami, N.R., Dreyer, D.: Internalizing relational parametricity in the extensional calculus of constructions. In: CSL, pp. 432–451 (2013)
Mac Lane, S.: Categories for the Working Mathematician, vol. 5. Springer, New York (1998)
Martin-Löf, P.: An intuitionistic theory of types. In: Twenty-Five Years of Constructive Type Theory (1972)
O’Hearn, P.W., Tennent, R.D.: Parametricity and local variables. J. ACM 42(3), 658–709 (1995)
Polonsky, A.: Extensionality of lambda-*. In: Herbelin, H., Letouzey, P., Sozeau, M. (eds.) 20th International Conference on Types for Proofs and Programs (TYPES 2014). Leibniz International Proceedings in Informatics (LIPIcs), vol. 39, pp. 221–250. Schloss Dagstuhl-Leibniz-Zentrum für Informatik, Dagstuhl (2015)
Reynolds, J.: Types, abstraction and parametric polymorphism. In: Mason, R.E.A. (ed.) Information Processing 1983, pp. 513–523. North-Holland, Amsterdam (1983)
Robinson, E., Rosolini, G.: Reflexive graphs and parametric polymorphism. In: LICS, pp. 364–371 (1994)
Strachey, C.: Fundamental concepts in programming languages. High. Order Symbolic Comput. 13(1–2), 11–49 (2000)
The Univalent Foundations Program: Homotopy Type Theory: Univalent Foundations of Mathematics (2013). http://homotopytypetheory.org/book
Voevodsky, V.: The equivalence axiom and univalent models of type theory. Talk at CMU on 4 February 2010 (2010). http://arxiv.org/abs/1402.5556
Wadler, P.: Theorems for free! In: FPCA, pp. 347–359 (1989)
Wadler, P.: The Girard-Reynolds isomorphism (second edition). Theoret. Comput. Sci. 375(1–3), 201–226 (2007)
Acknowledgements
We thank Bob Atkey, Peter Hancock and the anonymous reviewers for helpful discussions and comments.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
A Proofs from Section 5
A Proofs from Section 5
Proof
(of Theorem 22 ). The proof is done by induction on type judgements. For type variables, all statements are trivial. For arrow types, this is Propositions 8 and 20.
It remains to prove (ii), (iii) and (iv) for \(\forall \)-types. In this case we only need to produce maps in both directions — they will automatically compose to the identity by proof-irrelevance of 2-relations. The structure of the proof is the same for all of the three points.
For (ii) consider \((\tau _0,\rho _0, \tau _1, \rho _1)\in \mathsf {Eq}_{\Vert }(\llbracket \forall X.T \rrbracket _{1}\bar{R})(f,g,h,l)\). We want to show that \((\varPsi (\tau _0),\rho _0,\varPsi (\tau _1),\rho _1)\in \llbracket \forall X.T \rrbracket _{2}\mathsf {Eq}_{\Vert }(\bar{R})(f,g,h,l)\), i.e. that for every 2-relation Q,
By condition A1.1, we have
and using the equalities \((f_1 \mathsf {Eq}Q_{00}, \tau _0 \mathsf {Eq}Q_{10}, h_1 \mathsf {Eq}Q_{01}, \tau _1 \mathsf {Eq}Q_{11})\), we can show
We now transport across this equality to finish the argument.
Finally, in the other direction, if \((\rho _0,\rho _1,\rho _2,\rho _3)\in \llbracket \forall X.T \rrbracket _{2}\mathsf {Eq}_{\Vert }(\bar{R})(f,g,h,l)\), then \((\varTheta (\rho _0), \rho _1,\varTheta (\rho _2),\rho _3)\in \mathsf {Eq}_{\Vert }(\llbracket \forall X.T \rrbracket _{1}\bar{R})(f,g,h,l)\) by straightforward calculation and the definition of \(\llbracket \forall X.T \rrbracket _{2}\).
The case (iii) is just the same as the previous case, the only difference is that we now transport starting from condition (A1.2) and adjust the equalities along which we transport.
The last case (iv) is more complicated. Consider \((\tau _0,\tau _1, \rho _0, \rho _1)\in \mathbf {C}(\llbracket \forall X.T \rrbracket _{1} \bar{R})(f,g,h,l)\). We want to show that \((\varPsi (\tau _0),\varPsi (\tau _1),\rho _0,\rho _1)\in \llbracket \forall X.T \rrbracket _{2}\mathbf {C}(\bar{R}) (f,g,h,l)\), i.e. that for every 2-relation Q,
By condition A1.3, we have
and using the equalities
we can show
We can now transport across this equality to finish the argument. This requires the use of Lemma 23 (i) and (ii), and the fact that \((\tau _0,\tau _1, \rho _0, \rho _1)\in \mathbf {C}(\llbracket \forall X.T \rrbracket _{1}\bar{R})(f,g,h,l)\).
Finally, In the other direction, if \((\rho _0,\rho _1,\rho _2,\rho _3)\in \) \(\llbracket \forall X.T \rrbracket _{2}\mathbf {C}(\bar{R})(f,g,h,l)\), then \((\varTheta (\rho _0), \varTheta (\rho _1),\rho _2,\rho _3)\in \mathbf {C}(\llbracket \forall X.T \rrbracket _{1}\bar{R})(f,g,h,l)\) by straightforward calculation and the definition of \(\llbracket \forall X.T \rrbracket _{2}\). Â Â Â \(\square \)
Proof
(of Lemma 23 ).
-
(i)
Since
$$(f_1 R, f_1 \mathsf {Eq}R_0, f_1 R, f_1 \mathsf {Eq}R_1)\in \llbracket T \rrbracket _{2}(\mathbf {C}\circ \mathsf {Eq}(\vec {A}), \mathsf {Eq}_{=}(R))(f_0 R_0, f_0 R_1, g_0 R_0, g_0 R_1)$$and \(\llbracket T \rrbracket _{2}(\mathbf {C}\circ \mathsf {Eq}(\vec {A}), \mathsf {Eq}_{=}(R))=\llbracket T \rrbracket _{2}(\mathsf {Eq}_{=} \circ \mathsf {Eq}(\vec {A}), \mathsf {Eq}_{=}(R))\cong \mathsf {Eq}_{=}(\llbracket T \rrbracket _{1}(\mathsf {Eq}\vec {A},R))\), by Theorem 22 (iii), the thesis follows.
-
(ii)
By assumption,
$$ (f_1 R, \phi \mathsf {Eq}R_0, g_1 R, \phi \mathsf {Eq}R_1)\in \llbracket T \rrbracket _{2}(\mathsf {Eq}_{=}\mathsf {Eq}\vec {A},\mathsf {Eq}_{=}R)(f_0 R_0, f_1 R_1, g_0 R_0, g_0 R_1) . $$By Theorem 22 (iii), \(\llbracket T \rrbracket _{2}(\mathsf {Eq}_{=}\mathsf {Eq}\vec {A},\mathsf {Eq}_{=}R)\cong \mathsf {Eq}_{=}(\llbracket T \rrbracket _{1}(\mathsf {Eq}\vec {A},R))\), hence we have \(\mathsf {tr}((\phi \mathsf {Eq}R_0)^{-1}, (g_1 \mathsf {Eq}R_1)^{-1})g_1 R = \mathsf {tr}(f_1 \mathsf {Eq}R_0, \phi \mathsf {Eq}R_1)f_1 R\). If we now transport \((f_1 R, \phi \mathsf {Eq}R_0, g_1 R, \phi \mathsf {Eq}R_1)\) along the equality proof \(((f_1 \mathsf {Eq}R_0)^{-1},\) \((f_1 \mathsf {Eq}R_1)^{-1},(\phi \mathsf {Eq}R_0)^{-1},(g_0 \mathsf {Eq}R_1)^{-1})\), the result follows.
-
(iii)
By assumption,
$$ (g_1 Q_{r0}, g_1 Q_{0r}, g_1 Q_{r1}, g_1 Q_{1r})\in \llbracket T \rrbracket _{2}(\mathsf {Eq}_2 \vec {A}, Q)(g_0 Q_{00}, g_0 Q_{10}, g_0 Q_{01}, g_0 Q_{11}) $$We can transport \((g_1 Q_{r0}, g_1 Q_{0r}, g_1 Q_{r1}, g_1 Q_{1r})\) along the equality \(((\phi \mathsf {Eq}Q_{00})^{-1},\) \((g_1 \mathsf {Eq}Q_{10})^{-1},(g_1 \mathsf {Eq}Q_{01})^{-1},(g_1 \mathsf {Eq}Q_{11})^{-1})\). By (i) and (ii), condition (A0), and \(\llbracket T \rrbracket _{2}(\mathsf {Eq}_2 \vec {A},Q)=\llbracket T \rrbracket _{2}(\mathbf {C}\circ \mathsf {Eq}\vec {A},Q)\), the thesis follows. Â Â Â \(\square \)
Proof
(of Theorem 25 ). We need to check that the \(\beta \)- and \(\eta \)-rules for both term and type abstraction are respected. For term abstraction, this follows from Lemmas 13 and 16.
We next consider the \(\eta \)-rule for type abstraction. Let \(\varGamma ; \varDelta \vdash t : \forall X . T\) be given. Let \(\llbracket t \rrbracket _{0}\vec {A}\gamma = (f_0,f_1)\). Showing \(\llbracket \varLambda X . t[X] \rrbracket _{0} \equiv \llbracket t \rrbracket _{0}\) means giving \(p_0 : \mathsf {Id}_{}(\lambda A.f_0 A, f_0)\) and . For \(p_0\), we choose \(p_0 = \mathsf {refl}\). Note that
under the equivalence with respect to \(\tau = \mathsf {refl}\), and
In this way we can conclude
Similarly, things are exactly lined up to make \(\mathsf {tr}(\mathsf {pair}_{=}(p_0, p_1))(\llbracket \varLambda X . t[X] \rrbracket _{1}) \equiv \llbracket t \rrbracket _{1}\) trivial.
For the \(\beta \)-rule, consider \(\varGamma ,X \vdash t:T\). We can use \(p_{\bar{A}} = (\llbracket t \rrbracket _{1}\mathsf {Eq}(\vec {A},\llbracket S \rrbracket _{0}\vec {A})\varTheta _{\varDelta ,0}(\mathsf {refl}(\gamma )))^{-1}\) to prove \(\llbracket (\varLambda X . t)[S] \rrbracket _{0}\bar{A}\gamma \equiv \llbracket t[X \mapsto S] \rrbracket _{0}\bar{A}\gamma \). This makes \(\mathsf {tr}(p_{\bar{R}_0})(\llbracket (\varLambda X . t)[S] \rrbracket _{1})\bar{R}\bar{\gamma } \equiv \llbracket t[X \mapsto S] \rrbracket _{1}\bar{R}\bar{\gamma }\) trivial, again using Lemma 1.    \(\square \)
Rights and permissions
Copyright information
© 2016 Springer International Publishing Switzerland
About this chapter
Cite this chapter
Ghani, N., Nordvall Forsberg, F., Orsanigo, F. (2016). Proof-Relevant Parametricity. In: Lindley, S., McBride, C., Trinder, P., Sannella, D. (eds) A List of Successes That Can Change the World. Lecture Notes in Computer Science(), vol 9600. Springer, Cham. https://doi.org/10.1007/978-3-319-30936-1_6
Download citation
DOI: https://doi.org/10.1007/978-3-319-30936-1_6
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-30935-4
Online ISBN: 978-3-319-30936-1
eBook Packages: Computer ScienceComputer Science (R0)