Reynold's parametricity theory captures the property that parametrically polymorphic functions behave uniformly: they produce related results on related instantiations. In dependently typed programming languages, such relations and uniformity proofs can be expressed internally, and generated as a program translation. We present a new parametricity translation for a significant fragment of Coq. Previous translations of parametrically polymorphic propositions allowed non-uniformity. For example, on related instantiations, a function may return propositions that are logically inequivalent (e.g. True and False). We show that uniformity of polymorphic propositions is not achievable in general. Nevertheless, our translation produces proofs that the two propositions are logically equivalent and also that any two proofs of those propositions are related. This is achieved at the cost of potentially requiring more assumptions on the instantiations, requiring them to be isomorphic in the worst case. Our translation augments the previous one for Coq by carrying and compositionally building extra proofs about parametricity relations. It is made easier by a new method for translating inductive types and pattern matching. The new method builds upon and generalizes previous such translations for dependently typed programming languages. Using reification and reflection, we have implemented our translation as Coq programs 1 . We obtain several stronger free theorems applicable to an ongoing compiler-correctness project. Previously, proofs of some of these theorems took several hours to finish. Krishnaswami and Dreyer [2013] summarize Reynold's work on parametricity in the following perfect way: Reynolds [1983] famously introduced the concept of relational parametricity with a fable about data abstraction. Professors Bessel and Descartes, each teaching a class on complex numbers, defined them differently in the first lecture, the former using polar coordinates and the latter using (of course) cartesian coordinates. But despite accidentally trading sections after the first lecture, they never taught their students anything false, since after the first class, both professors proved all their theorems in terms of the defined operations on complex numbers, and never in terms of their underlying coordinate representation. Reynolds formalized this idea by giving a semantics for System F in which each type denoted not just a set of well-formed terms, but a logical relation between them, defined recursively on the type structure of the language. Then, the fact that well-typed client programs were insensitive to a specific choice of implementation could be formalized in terms of their taking logically related inputs to logically related results. Since the two constructions of the complex numbers share the same interface, and it is easy to show they are logically related at that interface, any client of the interface must return equivalent results regardless of which implementation of the interface is used. In Reynold's work and subsequent work for other modern languages (e.g. OCaml [Crary 2017]), the logical relations for types are meta-theoretic (not defined in the programming language being studied). In contrast, in dependently typed programming languages such as Coq, one can express * abhishek.anand.iitg@gmail.com 1 https://github.com/aa755/paramcoq-iff Proc.
The parametricity translation of REF extends the logical relation on propositions to force that related propositions are logically equivalent.
Revisiting Parametricity: Inductives and Uniformity of Propositions
ArXiv
ArXiv
Computer Science