Journal of Automated Reasoning

, Volume 49, Issue 2, pp 141–159 | Cite as

Strongly Typed Term Representations in Coq

  • Nick BentonEmail author
  • Chung-Kil Hur
  • Andrew J. Kennedy
  • Conor McBride


There are two approaches to formalizing the syntax of typed object languages in a proof assistant or programming language. The extrinsic approach is to first define a type that encodes untyped object expressions and then make a separate definition of typing judgements over the untyped terms. The intrinsic approach is to make a single definition that captures well-typed object expressions, so ill-typed expressions cannot even be expressed. Intrinsic encodings are attractive and naturally enforce the requirement that metalanguage operations on object expressions, such as substitution, respect object types. The price is that the metalanguage types of intrinsic encodings and operations involve non-trivial dependency, adding significant complexity. This paper describes intrinsic-style formalizations of both simply-typed and polymorphic languages, and basic syntactic operations thereon, in the Coq proof assistant. The Coq types encoding object-level variables (de Bruijn indices) and terms are indexed by both type and typing environment. One key construction is the boot-strapping of definitions and lemmas about the action of substitutions in terms of similar ones for a simpler notion of renamings. In the simply-typed case, this yields definitions that are free of any use of type equality coercions. In the polymorphic case, some substitution operations do still require type coercions, which we at least partially tame by uniform use of heterogeneous equality.


The Coq proof assistant de Bruijn indices Typed object languages 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Adams, R.: Formalized metatheory with terms represented by an indexed family of types. In: Types for Proofs and Programs. Lecture Notes in Computer Science, vol. 3839, pp. 1–16. Springer (2006)Google Scholar
  2. 2.
    Altenkirch, T., Reus, B.: Monadic presentations of lambda terms using generalized inductive types. In: Computer Science Logic, 13th International Workshop (CSL’99). Lecture Notes in Computer Science, vol. 1683, pp. 453–468. Springer (1999)Google Scholar
  3. 3.
    Benton, N., Hur, C.K.: Biorthogonality, step-indexing and compiler correctness. In: Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming (ICFP’09), pp. 97–108. ACM (2009)Google Scholar
  4. 4.
    Benton, N., Hur, C.K.: Realizability and compositional compiler correctness for a polymorphic language. Tech. Rep. MSR-TR-2010-62, Microsoft Research (2010)Google Scholar
  5. 5.
    Benton, N., Kennedy, A.J., Varming, C.: Some domain theory and denotational semantics in Coq. In: Theorem Proving in Higher Order Logics, 22nd International Conference (TPHOLs’09). Lecture Notes in Computer Science, vol. 5674, pp. 115–130. Springer (2009)Google Scholar
  6. 6.
    Bird, R., Meertens, L.: Nested datatypes. In: Proceedings of the 4th International Conference on Mathematics of Program Construction (MPC’98). Lecture Notes in Computer Science, vol. 1422, pp. 52–67. Springer (1998)Google Scholar
  7. 7.
    Bird, R., Paterson, R.: de Bruijn notation as a nested datatype. J. Funct. Program. 9, 77–91 (1999)MathSciNetzbMATHCrossRefGoogle Scholar
  8. 8.
    Brady, E., Hammond, K.: A verified staged interpreter is a verified compiler. In: Proceedings of the 5th International Conference on Generative Programming and Component Engineering (GPCE’06), pp. 111–120. ACM (2006)Google Scholar
  9. 9.
    Chapman, J.: Type theory should eat itself. In: International Workshop on Logical Frameworks and Meta-Languages: Theory and Practice (LFMTP’08). Electr. Notes Theor. Comput. Sci., vol. 228, pp. 21–36. Elsevier (2009)Google Scholar
  10. 10.
    Cheney, J., Hinze, R.: First-class phantom types. Tech. Rep. TR2003-1901, Cornell University (2003)Google Scholar
  11. 11.
    Chlipala, A.: Parametric higher-order abstract syntax for mechanized semantics. In: Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP’08), pp. 143–156. ACM (2008)Google Scholar
  12. 12.
    Coquand, C.: A formalized proof of the soundness and completeness of a simply typed lambda-calculus with explicit substitutions. Higher-Order and Symb. Comp. 15, 57–90 (2002)zbMATHCrossRefGoogle Scholar
  13. 13.
    Danielsson, N.A.: A formalization of a dependently typed language as an inductive-recursive family. In: Types for Proofs and Programs. Lecture Notes in Computer Science, vol. 4502, pp. 93–109. Springer (2007)Google Scholar
  14. 14.
    Girard, J.Y., Lafont, Y., Taylor, P.: Proofs and Types. Cambridge Tracts in Theoretical Computer Science, vol. 7. CUP (1989)Google Scholar
  15. 15.
    Goguen, H., McKinna, J.: Candidates for substitution. Tech. Rep. ECS-LFCS-97-358, University of Edinburgh (1997)Google Scholar
  16. 16.
    Harper, R., Honsell, F., Plotkin, G.: A framework for defining logics. J. ACM 40(1), 143–184 (1993)MathSciNetzbMATHCrossRefGoogle Scholar
  17. 17.
    Hirschowitz, A., Maggesi, M.: Nested abstract syntax in Coq. J. Autom. Reason. (2010). doi: 10.1007/s10817-010-9207-9 zbMATHGoogle Scholar
  18. 18.
    Hur, C.-K.: Heq: A Coq library for heterogeneous equality. (2010). Accessed Feb 2011
  19. 19.
    Kennedy, A., Russo, C.: Generalized algebraic datatypes and object oriented programming. In: ACM Conference on Object Oriented Programming Systems, Languages and Applications (OOPSLA’05), pp. 21–40. ACM (2005)Google Scholar
  20. 20.
    McBride, C.: Elimination with a motive. In: Types for Proofs and Programs. Lecture Notes in Computer Science, vol. 2277, pp. 197–216. Springer (2002)Google Scholar
  21. 21.
    McBride, C.: Type preserving renaming and substitution. (2005). Accessed Feb 2011
  22. 22.
    McBride, C.: Outrageous but meaningful coincidences (dependently type-safe syntax and evaluation). In: Proceedings of the 6th ACM SIGPLAN Workshop on Generic Programming (WGP’10). ACM (2010)Google Scholar
  23. 23.
    McBride, C., McKinna, J.: The view from the left. J. Funct. Program. 14(1), 69–111 (2004)MathSciNetzbMATHCrossRefGoogle Scholar
  24. 24.
    Sheard, T.: Languages of the future. In: Companion to the 19th ACM Conference on Object Oriented Programming Systems, Languages and Applications (OOPSLA’04), pp. 116–119. ACM (2004)Google Scholar
  25. 25.
    Sozeau, M.: PROGRAM-ing finger trees in COQ. In: Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming (ICFP’07), pp. 13–24. ACM (2007)Google Scholar
  26. 26.
    Sozeau, M.: A dependently-typed formalization of simply-typed lambda-calculus: substitution, denotation, normalization. (2007). Accessed Feb 2011
  27. 27.
    Xi, H., Chen, C., Chen, G.: Guarded recursive datatype constructors. In: Proceedings of the 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’03), pp. 224–235. ACM (2003)Google Scholar

Copyright information

© Springer Science+Business Media B.V. 2011

Authors and Affiliations

  • Nick Benton
    • 1
    Email author
  • Chung-Kil Hur
    • 2
  • Andrew J. Kennedy
    • 1
  • Conor McBride
    • 3
  1. 1.Microsoft ResearchCambridgeUK
  2. 2.Max Planck Institute for Software SystemsSaarbrückenGermany
  3. 3.Department of Computer and Information SciencesUniversity of StrathclydeGlasgowScotland

Personalised recommendations