Relational Parametricity and Quotient Preservation for Modular (Co)datatypes

  • Andreas LochbihlerEmail author
  • Joshua SchneiderEmail author
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10895)


Bounded natural functors (BNFs) provide a modular framework for the construction of (co)datatypes in higher-order logic. Their functorial operations, the mapper and relator, are restricted to a subset of the parameters, namely those where recursion can take place. For certain applications, such as free theorems, data refinement, quotients, and generalised rewriting, it is desirable that these operations do not ignore the other parameters. In this paper, we generalise BNFs such that the mapper and relator act on both covariant and contravariant parameters. Our generalisation, BNF\(_{\!\text {CC}}\), is closed under functor composition and least and greatest fixpoints. In particular, every (co)datatype is a BNF\(_{\!\text {CC}}\). We prove that subtypes inherit the BNF\(_{\!\text {CC}}\) structure under conditions that generalise those for the BNF case. We also identify sufficient conditions under which a BNF\(_{\!\text {CC}}\) preserves quotients. Our development is formalised abstractly in Isabelle/HOL in such a way that it integrates seamlessly with the existing parametricity infrastructure.



The authors thank Dmitriy Traytel, Andrei Popescu, and the anonymous reviewers for inspiring discussions and suggestions how to improve the presentation. The authors are listed alphabetically.

Supplementary material

470383_1_En_24_MOESM1_ESM.pdf (155 kb)
Supplementary material 1 (pdf 154 KB)


  1. 1.
    Adámek, J., Gumm, H.P., Trnková, V.: Presentation of set functors: a coalgebraic perspective. J. Log. Comput. 20, 991–1015 (2010)MathSciNetCrossRefGoogle Scholar
  2. 2.
    Anand, A., Morrisett, G.: Revisiting parametricity: inductives and uniformity of propositions. CoRR abs/1705.01163 (2017).
  3. 3.
    Atkey, R., Ghani, N., Johann, P.: A relationally parametric model of dependent type theory. In: POPL 2014, pp. 503–515. ACM (2014)Google Scholar
  4. 4.
    Basin, D., Lochbihler, A., Sefidgar, S.R.: CryptHOL: game-based proofs in higher-order logic. Cryptology ePrint Archive: Report 2017/753 (2017).
  5. 5.
    Bernardy, J.P., Jansson, P., Paterson, R.: Proofs for free: parametricity for dependent types. J. Funct. Program. 22(2), 107–152 (2012)MathSciNetCrossRefGoogle Scholar
  6. 6.
    Biendarra, J.: Functor-preserving type definitions in Isabelle/HOL. Bachelor thesis, Fakultät für Informatik, Technische Universität München (2015)Google Scholar
  7. 7.
    Blanchette, J.C., et al.: Truly modular (Co)datatypes for Isabelle/HOL. In: Klein, G., Gamboa, R. (eds.) ITP 2014. LNCS, vol. 8558, pp. 93–110. Springer, Cham (2014). Scholar
  8. 8.
    Blanchette, J.C., Meier, F., Popescu, A., Traytel, D.: Foundational nonuniform (co)datatypes for higher-order logic. In: LICS 2017, pp. 1–12. IEEE (2017)Google Scholar
  9. 9.
    Cohen, C., Dénès, M., Mörtberg, A.: Refinements for free!. In: Gonthier, G., Norrish, M. (eds.) CPP 2013. LNCS, vol. 8307, pp. 147–162. Springer, Cham (2013). Scholar
  10. 10.
    Delaware, B., Pit-Claudel, C., Gross, J., Chlipala, A.: Fiat: deductive synthesis of abstract data types in a proof assistant. In: POPL 2015, pp. 689–700. ACM (2015)Google Scholar
  11. 11.
    Gilcher, J., Lochbihler, A., Traytel, D.: Conditional parametricity in Isabelle/HOL (extended abstract). Poster at TABLEAU/FroCoS/ITP 2017 (2017).
  12. 12.
    Gumm, H.P.: Functors for coalgebras. Algebra Univ. 45, 135–147 (2001)MathSciNetzbMATHGoogle Scholar
  13. 13.
    Gunter, E.L.: Why we can’t have SML-style datatype declarations in HOL. In: TPHOLs 1992. IFIP Transactions, vol. A-20, pp. 561–568. Elsevier, North-Holland (1992)Google Scholar
  14. 14.
    Haftmann, F., Krauss, A., Kunčar, O., Nipkow, T.: Data refinement in Isabelle/HOL. In: Blazy, S., Paulin-Mohring, C., Pichardie, D. (eds.) ITP 2013. LNCS, vol. 7998, pp. 100–115. Springer, Heidelberg (2013). Scholar
  15. 15.
    Hölzl, J., Lochbihler, A., Traytel, D.: A formalized hierarchy of probabilistic system types. In: Urban, C., Zhang, X. (eds.) ITP 2015. LNCS, vol. 9236, pp. 203–220. Springer, Cham (2015). Scholar
  16. 16.
    Homeier, P.V.: A design structure for higher order quotients. In: Hurd, J., Melham, T. (eds.) TPHOLs 2005. LNCS, vol. 3603, pp. 130–146. Springer, Heidelberg (2005). Scholar
  17. 17.
    Huffman, B., Kunčar, O.: Lifting and Transfer: a modular design for quotients in Isabelle/HOL. In: Gonthier, G., Norrish, M. (eds.) CPP 2013. LNCS, vol. 8307, pp. 131–146. Springer, Cham (2013). Scholar
  18. 18.
    Kaliszyk, C., Urban, C.: Quotients revisited for Isabelle/HOL. In: SAC 2011, pp. 1639–1644. ACM (2011)Google Scholar
  19. 19.
    Keller, C., Lasson, M.: Parametricity in an impredicative sort. CoRR abs/1209.6336 (2012).
  20. 20.
    Kunčar, O.: Types, abstraction and parametric polymorphism in higher-order logic. Ph.D. thesis, Fakultät für Informatik, Technische Universität München (2016)Google Scholar
  21. 21.
    Lammich, P.: Automatic data refinement. In: Blazy, S., Paulin-Mohring, C., Pichardie, D. (eds.) ITP 2013. LNCS, vol. 7998, pp. 84–99. Springer, Heidelberg (2013). Scholar
  22. 22.
    Lammich, P., Lochbihler, A.: Automatic refinement to efficient data structures: a comparison of two approaches. J. Autom. Reasoning (2018).
  23. 23.
    Leino, K.R.M.: Dafny: an automatic program verifier for functional correctness. In: Clarke, E.M., Voronkov, A. (eds.) LPAR 2010. LNCS (LNAI), vol. 6355, pp. 348–370. Springer, Heidelberg (2010). Scholar
  24. 24.
    Lochbihler, A.: CryptHOL. Archive of Formal Proofs (2017)., Formal proof development
  25. 25.
    Lochbihler, A., Schneider, J.: Bounded natural functors with covariance and contravariance. Archive of Formal Proofs (2018)., Formal proof development
  26. 26.
    Maurer, U.: Indistinguishability of random systems. In: Knudsen, L.R. (ed.) EUROCRYPT 2002. LNCS, vol. 2332, pp. 110–132. Springer, Heidelberg (2002). Scholar
  27. 27.
    Mitchell, J.C.: Representation independence and data abstraction. In: POPL 1986, pp. 263–276. ACM (1986)Google Scholar
  28. 28.
    de Moura, L., Kong, S., Avigad, J., van Doorn, F., von Raumer, J.: The Lean theorem prover (System Description). In: Felty, A.P., Middeldorp, A. (eds.) CADE 2015. LNCS (LNAI), vol. 9195, pp. 378–388. Springer, Cham (2015). Scholar
  29. 29.
    Norell, U.: Towards a practical programming language based on dependent type theory. Ph.D. thesis, Department of Computer Science and Engineering, Chalmers University of Technology (2007)Google Scholar
  30. 30.
    Owre, S., Shankar, N.: Abstract datatypes in PVS. Technical Report CSL-93-9R, Computer Science Laboratory, SRI International (1993)Google Scholar
  31. 31.
    Paulin-Mohring, C.: Inductive definitions in the system Coq – rules and properties. In: Bezem, M., Groote, J.F. (eds.) TLCA 1993. LNCS, vol. 664, pp. 328–345. Springer, Heidelberg (1993). Scholar
  32. 32.
    Popescu, A.: Personal communication (2017)Google Scholar
  33. 33.
    Reynolds, J.C.: Types, abstraction and parametric polymorphism. In: IFIP 1983. Information Processing, vol. 83, pp. 513–523. IFIP, North-Holland (1983)Google Scholar
  34. 34.
    Rutten, J.J.M.M.: Universal coalgebra: a theory of systems. Theor. Comput. Sci. 249(1), 3–80 (2000)MathSciNetCrossRefGoogle Scholar
  35. 35.
    Schneider, J.: Formalising the run-time costs of HOL programs. Master’s thesis, Department of Computer Science, ETH Zurich (2017)Google Scholar
  36. 36.
    Slind, K., Norrish, M.: A brief overview of HOL4. In: Mohamed, O.A., Muñoz, C., Tahar, S. (eds.) TPHOLs 2008. LNCS, vol. 5170, pp. 28–32. Springer, Heidelberg (2008). Scholar
  37. 37.
    Sozeau, M.: A new look at generalized rewriting in type theory. J. Formalized Reasoning 2(1), 41–62 (2009)MathSciNetzbMATHGoogle Scholar
  38. 38.
    Traytel, D., Popescu, A., Blanchette, J.C.: Foundational, compositional (co)datatypes for higher-order logic. In: LICS 2012, pp. 596–605. IEEE (2012)Google Scholar
  39. 39.
    Wadler, P.: Theorems for free! In: FPCA 1989, pp. 347–359. ACM (1989)Google Scholar

Copyright information

© Springer International Publishing AG, part of Springer Nature 2018

Authors and Affiliations

  1. 1.Institute of Information Security, Department of Computer ScienceETH ZürichZürichSwitzerland

Personalised recommendations