Skip to main content

Shallow Embedding of Type Theory is Morally Correct

  • Conference paper
  • First Online:
Mathematics of Program Construction (MPC 2019)

Abstract

There are multiple ways to formalise the metatheory of type theory. For some purposes, it is enough to consider specific models of a type theory, but sometimes it is necessary to refer to the syntax, for example in proofs of canonicity and normalisation. One option is to embed the syntax deeply, by using inductive definitions in a proof assistant. However, in this case the handling of definitional equalities becomes technically challenging. Alternatively, we can reuse conversion checking in the metatheory by shallowly embedding the object theory. In this paper, we consider the standard model of a type theoretic object theory in Agda. This model has the property that all of its equalities hold definitionally, and we can use it as a shallow embedding by building expressions from the components of this model. However, if we are to reason soundly about the syntax with this setup, we must ensure that distinguishable syntactic constructs do not become provably equal when shallowly embedded. First, we prove that shallow embedding is injective up to definitional equality, by modelling the embedding as a syntactic translation targeting the metatheory. Second, we use an implementation hiding trick to disallow illegal propositional equality proofs and constructions which do not come from the syntax. We showcase our technique with very short formalisations of canonicity and parametricity for Martin-Löf type theory. Our technique only requires features which are available in all major proof assistants based on dependent type theory.

This work was supported by the Thematic Excellence Programme, Industry and Digitization Subprogramme, NRDI Office, 2019 and by the European Union, co-financed by the European Social Fund (EFOP-3.6.2-16-2017-00013 and EFOP-3.6.3-VEKOP-16-2017-00002).

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Similar content being viewed by others

Notes

  1. 1.

    Or use an inductive type definition instead of a record.

References

  1. Abel, A., Öhman, J., Vezzosi, A.: Decidability of conversion for type theory in type theory. Proc. ACM Program. Lang. 2(POPL), 23 (2017)

    Article  Google Scholar 

  2. Altenkirch, T., Capriotti, P., Dijkstra, G., Kraus, N., Nordvall Forsberg, F.: Quotient inductive-inductive types. In: Baier, C., Dal Lago, U. (eds.) FoSSaCS 2018. LNCS, vol. 10803, pp. 293–310. Springer, Cham (2018). https://doi.org/10.1007/978-3-319-89366-2_16

    Chapter  Google Scholar 

  3. Altenkirch, T., Kaposi, A.: Type theory in type theory using quotient inductive types. In: Bodik, R., Majumdar, R. (eds.) Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, 20–22 January 2016, St. Petersburg, FL, USA, pp. 18–29. ACM (2016). https://doi.org/10.1145/2837614.2837638

  4. Altenkirch, T., Kaposi, A.: Normalisation by evaluation for type theory, in type theory. Logical Methods Comput. Sci. 13(4) (2017). https://doi.org/10.23638/LMCS-13(4:1)2017

  5. Anand, A., Boulier, S., Cohen, C., Sozeau, M., Tabareau, N.: Towards certified meta-programming with typed template-coq. In: Avigad, J., Mahboubi, A. (eds.) ITP 2018. LNCS, vol. 10895, pp. 20–39. Springer, Cham (2018). https://doi.org/10.1007/978-3-319-94821-8_2

    Chapter  Google Scholar 

  6. Bernardy, J.P., Jansson, P., Paterson, R.: Proofs for free – parametricity for dependent types. J. Funct. Program. 22(02), 107–152 (2012). https://doi.org/10.1017/S0956796812000056

    Article  MathSciNet  MATH  Google Scholar 

  7. Birkedal, L., Mogelberg, R.E., Schwinghammer, J., Stovring, K.: First steps in synthetic guarded domain theory: step-indexing in the topos of trees. In: 2011 IEEE 26th Annual Symposium on Logic in Computer Science, pp. 55–64. IEEE (2011)

    Google Scholar 

  8. Boulier, S., Pédrot, P.M., Tabareau, N.: The next 700 syntactical models of type theory. In: Proceedings of the 6th ACM SIGPLAN Conference on Certified Programs and Proofs, CPP 2017, pp. 182–194. ACM, New York (2017). https://doi.org/10.1145/3018610.3018620

  9. Brady, E.: Idris, a general-purpose dependently typed programming language: design and implementation. J. Funct. Program. 23(5), 552–593 (2013)

    Article  MathSciNet  Google Scholar 

  10. Chapman, J.: Type theory should eat itself. Electron. Notes Theor. Comput. Sci. 228, 21–36 (2009). https://doi.org/10.1016/j.entcs.2008.12.114

    Article  MATH  Google Scholar 

  11. Chlipala, A.: Parametric higher-order abstract syntax for mechanized semantics. In: Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming, ICFP 2008, pp. 143–156. ACM, New York (2008). https://doi.org/10.1145/1411204.1411226

  12. Cockx, J., Abel, A.: Sprinkles of extensionality for your vanilla type theory. In: TYPES 2016 (2016)

    Google Scholar 

  13. Cohen, C., Coquand, T., Huber, S., Mörtberg, A.: Cubical type theory: a constructive interpretation of the univalence axiom, December 2015

    Google Scholar 

  14. Coquand, T.: Canonicity and normalisation for dependent type theory. CoRR (2018). http://arxiv.org/abs/1810.09367

  15. Coquand, T., Huber, S., Sattler, C.: Homotopy canonicity for cubical type theory. In: Geuvers, H. (ed.) Proceedings of the 4th International Conference on Formal Structures for Computation and Deduction (FSCD 2019) (2019)

    Google Scholar 

  16. Danielsson, N.A.: A formalisation of a dependently typed language as an inductive-recursive family. In: Altenkirch, T., McBride, C. (eds.) TYPES 2006. LNCS, vol. 4502, pp. 93–109. Springer, Heidelberg (2007). https://doi.org/10.1007/978-3-540-74464-1_7

    Chapter  Google Scholar 

  17. Despeyroux, J., Felty, A., Hirschowitz, A.: Higher-Order Abstract Syntax in Coq. Technical Report RR-2556, INRIA, May 1995. https://hal.inria.fr/inria-00074124

    Google Scholar 

  18. Devriese, D., Piessens, F.: Typed syntactic meta-programming. In: Proceedings of the 2013 ACM SIGPLAN International Conference on Functional Programming (ICFP 2013). pp. 73–85. ACM, September 2013. https://doi.org/10.1145/2500365.2500575

  19. Diehl, L.: Fully Generic Programming over Closed Universes of Inductive-Recursive Types. Ph.D. thesis, Portland State University (2017)

    Google Scholar 

  20. Dybjer, P.: Internal type theory. In: Berardi, S., Coppo, M. (eds.) TYPES 1995. LNCS, vol. 1158, pp. 120–134. Springer, Heidelberg (1996). https://doi.org/10.1007/3-540-61780-9_66

    Chapter  Google Scholar 

  21. Hofmann, M.: Extensional concepts in intensional type theory. Thesis, University of Edinburgh, Department of Computer Science (1995)

    Google Scholar 

  22. Hofmann, M.: Syntax and semantics of dependent types. In: Semantics and Logics of Computation, pp. 79–130. Cambridge University Press (1997)

    Google Scholar 

  23. Hofmann, M.: Semantical analysis of higher-order abstract syntax. In: Proceedings of the 14th Annual IEEE Symposium on Logic in Computer Science, LICS 1999, p. 204. IEEE Computer Society, Washington (1999). http://dl.acm.org/citation.cfm?id=788021.788940

  24. Hou (Favonia), K.B., Finster, E., Licata, D.R., Lumsdaine, P.L.: A mechanization of the Blakers-Massey connectivity theorem in homotopy type theory. In: Proceedings of the 31st Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2016, pp. 565–574. ACM, New York (2016). https://doi.org/10.1145/2933575.2934545

  25. Huber, S.: Cubical Interpretations of Type Theory. Ph.D. thesis, University of Gothenburg (2016)

    Google Scholar 

  26. Jaber, G., Lewertowski, G., Pédrot, P.M., Sozeau, M., Tabareau, N.: The definitional side of the forcing. In: Logics in Computer Science, New York, United States, May 2016. https://doi.org/10.1145/2933575.2935320

  27. Kaposi, A., Huber, S., Sattler, C.: Gluing for type theory. In: Geuvers, H. (ed.) Proceedings of the 4th International Conference on Formal Structures for Computation and Deduction (FSCD 2019) (2019)

    Google Scholar 

  28. Kaposi, A., Kovács, A.: A syntax for higher inductive-inductive types. In: Kirchner, H. (ed.) 3rd International Conference on Formal Structures for Computation and Deduction (FSCD 2018). Leibniz International Proceedings in Informatics (LIPIcs), vol. 108, pp. 20:1–20:18. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany (2018). https://doi.org/10.4230/LIPIcs.FSCD.2018.20

  29. Kaposi, A., Kovács, A., Altenkirch, T.: Constructing quotient inductive-inductive types. Proc. ACM Program. Lang. 3(POPL), 2 (2019)

    Article  Google Scholar 

  30. Kaposi, A., Kovács, A., Kraus, N.: Formalisations in Agda using a morally correct shallow embedding, May 2019. https://bitbucket.org/akaposi/shallow/src/master/

  31. Licata, D.: Running circles around (in) your proof assistant; or, quotients that compute (2011). http://homotopytypetheory.org/2011/04/23/running-circles-around-in-your-proof-assistant/

  32. Martin-Löf, P.: An intuitionistic theory of types: predicative part. In: Rose, H., Shepherdson, J. (eds.) Logic Colloquium ’73, Proceedings of the Logic Colloquium, Studies in Logic and the Foundations of Mathematics, North-Holland, vol. 80, pp. 73–118 (1975)

    Chapter  Google Scholar 

  33. The Coq development team: The Coq proof assistant reference manual. LogiCal Project (2019). http://coq.inria.fr. version 8.9

  34. McBride, C.: Outrageous but meaningful coincidences: dependent type-safe syntax and evaluation. In: Oliveira, B.C.d.S., Zalewski, M. (eds.) Proceedings of the ACM SIGPLAN Workshop on Generic Programming, pp. 1–12. ACM (2010). https://doi.org/10.1145/1863495.1863497

  35. McBride, C., McKinna, J.: Functional pearl: I am not a number – I am a free variable. In: Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell, Haskell 2004, pp. 1–9. ACM, New York (2004). https://doi.org/10.1145/1017472.1017477. http://doi.acm.org/10.1145/1017472.1017477

  36. 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). https://doi.org/10.1007/978-3-319-21401-6_26

    Chapter  Google Scholar 

  37. Nordvall Forsberg, F.: Inductive-inductive definitions. Ph.D. thesis, Swansea University (2013)

    Google Scholar 

  38. Orton, I., Pitts, A.M.: Axioms for modelling cubical type theory in a topos. In: Talbot, J.M., Regnier, L. (eds.) 25th EACSL Annual Conference on Computer Science Logic (CSL 2016). Leibniz International Proceedings in Informatics (LIPIcs), vol. 62, pp. 24:1–24:19. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany (2016). https://doi.org/10.4230/LIPIcs.CSL.2016.24

  39. Pfenning, F., Elliott, C.: Higher-order abstract syntax. SIGPLAN Not. 23(7), 199–208 (1988). https://doi.org/10.1145/960116.54010

    Article  Google Scholar 

  40. Pientka, B., Dunfield, J.: Beluga: a framework for programming and reasoning with deductive systems (system description). In: Giesl, J., Hähnle, R. (eds.) IJCAR 2010. LNCS (LNAI), vol. 6173, pp. 15–21. Springer, Heidelberg (2010). https://doi.org/10.1007/978-3-642-14203-1_2

    Chapter  MATH  Google Scholar 

  41. Reynolds, J.C.: Types, abstraction and parametric polymorphism. In: Mason, R.E.A. (ed.) Information Processing 1983, Proceedings of the IFIP 9th World Computer Congress, Paris, 19–23 September 1983, pp. 513–523. Elsevier Science Publishers B. V. (North-Holland), Amsterdam (1983)

    Google Scholar 

  42. Tabareau, N., Tanter, É., Sozeau, M.: Equivalences for free. Proc. ACM Program. Lang. 1–29 (2018). https://hal.inria.fr/hal-01559073

    Article  Google Scholar 

  43. The Agda development team: Agda (2015). http://wiki.portal.chalmers.se/agda

  44. Wieczorek, P., Biernacki, D.: A Coq formalization of normalization by evaluation for Martin-Löf type theory. In: Proceedings of the 7th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2018, pp. 266–279. ACM, New York (2018). https://doi.org/10.1145/3167091

  45. Winterhalter, T., Sozeau, M., Tabareau, N.: Eliminating reflection from type theory. In: Proceedings of the 8th ACM SIGPLAN International Conference on Certified Programs and Proofs, pp. 91–103. ACM (2019)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Ambrus Kaposi .

Editor information

Editors and Affiliations

A The injectivity displayed model

A The injectivity displayed model

We list the components of the displayed model for the injectivity proof described in Sect. 5. We don’t write subscripts for metavariables and operators of the syntax, only for components of the displayed model (\(_1\), \(_2\), \(_{12}\), \(_{21}\) and \(_=\)).

figure dq
figure dr
figure ds
figure dt
figure du
figure dv
figure dw
figure dx
figure dy
figure dz

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Kaposi, A., Kovács, A., Kraus, N. (2019). Shallow Embedding of Type Theory is Morally Correct. In: Hutton, G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science(), vol 11825. Springer, Cham. https://doi.org/10.1007/978-3-030-33636-3_12

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-33636-3_12

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-33635-6

  • Online ISBN: 978-3-030-33636-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics