Document Open Access Logo

Deeper Shallow Embeddings

Authors Jacob Prinz, G. A. Kavvos, Leonidas Lampropoulos

Thumbnail PDF


  • Filesize: 0.6 MB
  • 18 pages

Document Identifiers

Author Details

Jacob Prinz
  • University of Maryland, College Park, MD, USA
G. A. Kavvos
  • University of Bristol, UK
Leonidas Lampropoulos
  • University of Maryland, College Park, MD, USA

Cite AsGet BibTex

Jacob Prinz, G. A. Kavvos, and Leonidas Lampropoulos. Deeper Shallow Embeddings. In 13th International Conference on Interactive Theorem Proving (ITP 2022). Leibniz International Proceedings in Informatics (LIPIcs), Volume 237, pp. 28:1-28:18, Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2022)


Deep and shallow embeddings are two popular techniques for embedding a language in a host language with complementary strengths and weaknesses. In a deep embedding, embedded constructs are defined as data in the host: this allows for syntax manipulation and facilitates metatheoretic reasoning, but is challenging to implement - especially in the case of dependently typed embedded languages. In a shallow embedding, by contrast, constructs are encoded using features of the host: this makes them quite straightforward to implement, but limits their use in practice. In this paper, we attempt to bridge the gap between the two, by presenting a general technique for extending a shallow embedding of a type theory with a deep embedding of its typing derivations. Such embeddings are almost as straightforward to implement as shallow ones, but come with capabilities traditionally associated with deep ones. We demonstrate these increased capabilities in a number of case studies; including a DSL that only holds affine terms, and a dependently typed core language with computational beta reduction that leverages function extensionality.

Subject Classification

ACM Subject Classification
  • Software and its engineering
  • Software and its engineering → General programming languages
  • Social and professional topics → History of programming languages
  • type theory
  • shallow embedding
  • deep embedding
  • Agda


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Thorsten Altenkirch and Ambrus Kaposi. Type theory in type theory using quotient inductive types. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 18-29. Association for Computing Machinery, 2016. URL:
  2. Thorsten Altenkirch and Ambrus Kaposi. Normalisation by Evaluation for Type Theory, in Type Theory. Logical Methods in Computer Science, 13(4), 2017. URL:
  3. Thorsten Altenkirch and Bernhard Reus. Monadic Presentations of Lambda Terms Using Generalized Inductive Types. In Jörg Flum and Mario Rodriguez-Artalejo, editors, Computer Science Logic, volume 1683 of Lecture Notes in Computer Science, pages 453-468, Berlin, Heidelberg, 1999. Springer Berlin Heidelberg. URL:
  4. Lennart Augustsson. Making edsls fly., 2012.
  5. Richard J. Boulton, Andrew D. Gordon, Michael J. C. Gordon, John Harrison, John Herbert, and John Van Tassel. Experience with embedding hardware description languages in HOL. In Victoria Stavridou, Thomas F. Melham, and Raymond T. Boute, editors, Theorem Provers in Circuit Design, Proceedings of the IFIP TC10/WG 10.2 International Conference on Theorem Provers in Circuit Design: Theory, Practice and Experience, Nijmegen, The Netherlands, 22-24 June 1992, Proceedings, volume A-10 of IFIP Transactions, pages 129-156. North-Holland, 1992. URL:
  6. Jacques Carette, Oleg Kiselyov, and Chung-Chieh Shan. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming, 19(5):509-543, 2009. URL:
  7. James Chapman. Type Theory Should Eat Itself. Electronic Notes in Theoretical Computer Science, 228:21-36, 2009. URL:
  8. Joonwon Choi, Muralidaran Vijayaraghavan, Benjamin Sherman, Adam Chlipala, and Arvind. Kami: A platform for high-level parametric hardware specification and its modular verification. Proc. ACM Program. Lang., 1(ICFP), August 2017. URL:
  9. Koen Claessen. Embedded Languages for Describing and Verifying Hardware. PhD thesis, Chalmers University of Technology, Gothenburg, Sweden, 2001. URL:
  10. Koen Claessen and John Hughes. Quickcheck: A lightweight tool for random testing of haskell programs. Proceedings of the ACM SIGPLAN International Conference on Functional Programming, ICFP, 46, January 2000. URL:
  11. Thierry Coquand. Canonicity and normalization for dependent type theory. Theoretical Computer Science, 777:184-191, 2019. URL:
  12. Nils Anders Danielsson. A formalisation of a dependently typed language as an inductive-recursive family. In Thorsten Altenkirch and Conor McBride, editors, Types for Proofs and Programs, International Workshop, TYPES 2006, Nottingham, UK, April 18-21, 2006, Revised Selected Papers, volume 4502 of Lecture Notes in Computer Science, pages 93-109. Springer, 2006. URL:
  13. Peter Dybjer and Anton Setzer. Indexed induction–recursion. The Journal of Logic and Algebraic Programming, 66(1):1-49, 2006. URL:
  14. Marcelo Fiore. Semantic analysis of normalisation by evaluation for typed lambda calculus. In Proceedings of the 4th ACM SIGPLAN international conference on Principles and Practice of Declarative Programming - PPDP '02, pages 26-37. ACM Press, 2002. URL:
  15. Jeremy Gibbons and Nicolas Wu. Folding domain-specific languages: deep and shallow embeddings (functional pearl). In Proceedings of the 19th ACM SIGPLAN international conference on Functional programming, pages 339-347. ACM, 2014. URL:
  16. Martin Hofmann. Syntax and Semantics of Dependent Types. In Andrew M. Pitts and P. Dybjer, editors, Semantics and Logics of Computation, pages 79-130. Cambridge University Press, 1997. URL:
  17. Paul Hudak and Donya Quick. The Haskell School of Music: From Signals to Symphonies. Cambridge University Press, 2018. URL:
  18. Ambrus Kaposi, András Kovács, and Nicolai Kraus. Shallow Embedding of Type Theory is Morally Correct. In Graham Hutton, editor, Mathematics of Program Construction, volume 11825 of Lecture Notes in Computer Science, pages 329-365, Cham, 2019. Springer International Publishing. URL:
  19. Leonidas Lampropoulos, Diane Gallois-Wong, Catalin Hritcu, John Hughes, Benjamin C. Pierce, and Li-yao Xia. Beginner’s Luck: a language for property-based generators. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Paris, France, January 18-20, 2017, pages 114-129, 2017. URL:, URL:
  20. Per Martin-Löf. Intuitionistic type theory, volume 1 of Studies in Proof Theory. Bibliopolis, 1984. Google Scholar
  21. Conor McBride. Outrageous but meaningful coincidences: Dependent type-safe syntax and evaluation. In Proceedings of the 6th ACM SIGPLAN Workshop on Generic Programming, WGP '10, pages 1-12, New York, NY, USA, 2010. Association for Computing Machinery. URL:
  22. Jonathan Ragan-Kelley, Connelly Barnes, Andrew Adams, Sylvain Paris, Frédo Durand, and Saman Amarasinghe. Halide: A language and compiler for optimizing parallelism, locality, and recomputation in image processing pipelines. SIGPLAN Not., 48(6):519-530, June 2013. URL:
  23. The Univalent Foundations Program. Homotopy Type Theory: Univalent Foundations of Mathematics., Institute for Advanced Study, 2013.
  24. Vasco T. Vasconcelos. Fundamentals of session types. Information and Computation, 217:52-70, 2012. URL:
  25. Brent Yorgey. Diagrams: A declarative dsl for creating vector graphics., 2013.
  26. Christina Zeller and Ivan Perez. Mobile game programming in haskell. In Donya Quick and Daniel Winograd-Cort, editors, Proceedings of the 7th ACM SIGPLAN International Workshop on Functional Art, Music, Modeling, and Design, FARM@ICFP 2019, Berlin, Germany, August 18-23, 2019, pages 37-48. ACM, 2019. URL:
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail