Skip to main content
Log in

Strongly Typed Term Representations in Coq

  • Published:
Journal of Automated Reasoning Aims and scope Submit manuscript

Abstract

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.

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

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Institutional subscriptions

Similar content being viewed by others

References

  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)

  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)

  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)

  4. Benton, N., Hur, C.K.: Realizability and compositional compiler correctness for a polymorphic language. Tech. Rep. MSR-TR-2010-62, Microsoft Research (2010)

  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)

  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)

  7. Bird, R., Paterson, R.: de Bruijn notation as a nested datatype. J. Funct. Program. 9, 77–91 (1999)

    Article  MathSciNet  MATH  Google Scholar 

  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)

  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)

  10. Cheney, J., Hinze, R.: First-class phantom types. Tech. Rep. TR2003-1901, Cornell University (2003)

  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)

  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)

    Article  MATH  Google Scholar 

  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)

  14. Girard, J.Y., Lafont, Y., Taylor, P.: Proofs and Types. Cambridge Tracts in Theoretical Computer Science, vol. 7. CUP (1989)

  15. Goguen, H., McKinna, J.: Candidates for substitution. Tech. Rep. ECS-LFCS-97-358, University of Edinburgh (1997)

  16. Harper, R., Honsell, F., Plotkin, G.: A framework for defining logics. J. ACM 40(1), 143–184 (1993)

    Article  MathSciNet  MATH  Google Scholar 

  17. Hirschowitz, A., Maggesi, M.: Nested abstract syntax in Coq. J. Autom. Reason. (2010). doi:10.1007/s10817-010-9207-9

    MATH  Google Scholar 

  18. Hur, C.-K.: Heq: A Coq library for heterogeneous equality. http://www.mpi-sws.org/~gil/Heq/ (2010). Accessed Feb 2011

  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)

  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)

  21. McBride, C.: Type preserving renaming and substitution. http://strictlypositive.org/ren-sub.pdf (2005). Accessed Feb 2011

  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)

  23. McBride, C., McKinna, J.: The view from the left. J. Funct. Program. 14(1), 69–111 (2004)

    Article  MathSciNet  MATH  Google Scholar 

  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)

  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)

  26. Sozeau, M.: A dependently-typed formalization of simply-typed lambda-calculus: substitution, denotation, normalization. http://mattam.org/research/publications/drafts/lambda-notes.pdf (2007). Accessed Feb 2011

  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)

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Nick Benton.

Additional information

Hur was supported by the Digiteo/Ile-de-France project COLLODI (2009-28HD).

Rights and permissions

Reprints and permissions

About this article

Cite this article

Benton, N., Hur, CK., Kennedy, A.J. et al. Strongly Typed Term Representations in Coq. J Autom Reasoning 49, 141–159 (2012). https://doi.org/10.1007/s10817-011-9219-0

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10817-011-9219-0

Keywords

Navigation