Abstract
Functional programming languages are particularly well-suited for building automated reasoning systems, since (among other reasons) a logical term is well modeled by an inductive type, traversing a term can be implemented generically as a higher-order combinator, and backtracking search is dramatically simplified by persistent datastructures. However, existing pure functional programming languages all suffer a major limitation in these domains: traversing a term requires time proportional to the tree size of the term as opposed to its graph size. This limitation would be particularly devastating when building automation for interactive theorem provers such as Lean and Coq, for which the exponential blowup of term-tree sizes has proved to be both common and difficult to prevent. All that is needed to recover the optimal scaling is the ability to perform simple operations on the memory addresses of terms, and yet allowing these operations to be used freely would clearly violate the basic premise of referential transparency. We show how to use dependent types to seal the necessary pointer-address manipulations behind pure functional interfaces while requiring only a negligible amount of additional trust. We have implemented our approach for the upcoming version (v4) of Lean, and our approach could be adopted by other languages based on dependent type theory as well.
Supplemental Material
Available for Download
This zip file contains a Lean4 file with all the examples from the paper, as well as a Python script to reproduce the experiments in the paper.
- Thorsten Altenkirch and Ambrus Kaposi. 2016. Type theory in type theory using quotient inductive types. ACM SIGPLAN Notices 51, 1 ( 2016 ), 18-29.Google Scholar
- Phil Bagwell. 2001. Ideal hash trees. Technical Report.Google Scholar
- Maksym Bortin and Christoph Lüth. 2010. Structured Formal Development with Quotient Types in Isabelle/HOL. In Intelligent Computer Mathematics, Serge Autexier, Jacques Calmet, David Delahaye, Patrick D. F. Ion, Laurence Rideau, Renaud Rioboo, and Alan P. Sexton (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 34-48.Google Scholar
- Ana Bove, Peter Dybjer, and Ulf Norell. 2009. A brief overview of Agda-a functional language with dependent types. In International Conference on Theorem Proving in Higher Order Logics. Springer, 73-78.Google Scholar
Digital Library
- Robert S Boyer and Warren A Hunt Jr. 2006. Function memoization and unique object representation for ACL2 functions. In Proceedings of the sixth international workshop on the ACL2 theorem prover and its applications. 81-89.Google Scholar
Digital Library
- Edwin Brady. 2013. Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of functional programming 23, 5 ( 2013 ), 552-593.Google Scholar
Cross Ref
- Thomas Braibant, Jacques-Henri Jourdan, and David Monniaux. 2014. Implementing and reasoning about hash-consed data structures in Coq. Journal of automated reasoning 53, 3 ( 2014 ), 271-304.Google Scholar
Digital Library
- Cyril Cohen. 2013. Pragmatic Quotient Types in Coq. In Interactive Theorem Proving-4th International Conference, ITP 2013, Rennes, France, July 22-26, 2013. Proceedings. Springer, 213-228. https://doi.org/10.1007/978-3-642-39634-2_17 Google Scholar
Digital Library
- Leonardo de Moura, Soonho Kong, Jeremy Avigad, Floris Van Doorn, and Jakob von Raumer. 2015. The Lean theorem prover (system description). In International Conference on Automated Deduction. Springer, 378-388.Google Scholar
Cross Ref
- Margaret A Ellis and Bjarne Stroustrup. 1990. The annotated C++ reference manual. Addison-Wesley.Google Scholar
- Phil Freeman. 2015. PureScript.Google Scholar
- François Garillot. 2011. Generic Proof Tools and Finite Group Theory. Ph.D. Dissertation.Google Scholar
- Jean Goubault. 1994. Implementing functional languages with fast equality, sets and maps: an exercise in hash consing. Journées Francophones des Langages Applicatifs (JFLA'93) ( 1994 ), 222-238.Google Scholar
- Rich Hickey. 2008. The Clojure programming language. In Proceedings of the 2008 symposium on Dynamic languages. 1-1.Google Scholar
Digital Library
- Martin Hofmann. 1995. Extensional concepts in intensional type theory. ( 1995 ).Google Scholar
- Gérard Huet. 1992. The Gallina specification language: A case study. In International Conference on Foundations of Software Technology and Theoretical Computer Science. Springer, 229-240.Google Scholar
Cross Ref
- Simon Peyton Jones. 2003. Haskell 98 language and libraries: the revised report. Cambridge University Press.Google Scholar
- Simon Peyton Jones, Simon Marlow, and Conal Elliott. 1999. Stretching the storage manager: weak pointers and stable names in Haskell. In Symposium on Implementation and Application of Functional Languages. Springer, 37-58.Google Scholar
- Matt Kaufmann and J. Strother Moore. 1997. An industrial strength theorem prover for a logic based on Common Lisp. IEEE Transactions on Software Engineering 23, 4 ( 1997 ), 203-213.Google Scholar
Digital Library
- Xavier Leroy, Damien Doligez, Alain Frisch, Jacques Garrigue, Didier Rémy, and Jérôme Vouillon. 2018. The OCaml system release 4.07: Documentation and user's manual. ( 2018 ).Google Scholar
- The mathlib Community. 2020. The lean mathematical library. In Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2020, New Orleans, LA, USA, January 20-21, 2020, Jasmin Blanchette and Catalin Hritcu (Eds.). ACM, 367-381. https://doi.org/10.1145/3372885.3373824 Google Scholar
Digital Library
- David CJ Matthews. 1985. Poly manual. ACM SIGPLAN Notices 20, 9 ( 1985 ), 52-76.Google Scholar
- James McGraw, Stephen Skedzielewski, Stephen Allan, D Grit, R Oldehoeft, J Glauert, I Dobes, and P Hohensee. 1983. SISAL: streams and iteration in a single-assignment language. Language reference manual, Version 1. Technical Report. Lawrence Livermore National Lab., CA (USA).Google Scholar
- Tobias Nipkow, Lawrence C Paulson, and Markus Wenzel. 2002. Isabelle/HOL: a proof assistant for higher-order logic. Vol. 2283. Springer Science & Business Media.Google Scholar
Digital Library
- Aleksey Nogin. 2002. Quotient Types: A Modular Approach. In Proceedings of the 15th International Conference on Theorem Proving in Higher Order Logics, Victor Carreño, César Muñoz, and Sofiène Tashar (Eds.). Springer-Verlag, 263-280. Available at http://nogin.org/papers/quotients.html.Google Scholar
Cross Ref
- Martin Odersky, Philippe Altherr, Vincent Cremet, Burak Emir, Sebastian Maneth, Stéphane Micheloud, Nikolay Mihaylov, Michel Schinz, Erik Stenman, and Matthias Zenger. 2004. An overview of the Scala programming language. Technical Report.Google Scholar
- Sam Owre, John M Rushby, and Natarajan Shankar. 1992. PVS: A prototype verification system. In International Conference on Automated Deduction. Springer, 748-752.Google Scholar
Cross Ref
- Sven-Bodo Scholz. 1994. Single Assignment C-Functional Programming Using Imperative Style. In In John Glauert (Ed.) : Proceedings of the 6th International Workshop on the Implementation of Functional Languages. University of East Anglia.Google Scholar
- Daniel Selsam, Sebastian Ullrich, and Leonardo de Moura. 2020. Tabled Typeclass Resolution. arXiv preprint arXiv: 2001. 04301 ( 2020 ).Google Scholar
- Matthieu Sozeau and Nicolas Oury. 2008. First-class type classes. In International Conference on Theorem Proving in Higher Order Logics. Springer, 278-293.Google Scholar
Digital Library
- Guy Steele. 1990. Common LISP: the language. Elsevier.Google Scholar
- David Turner. 1986. An overview of Miranda. ACM Sigplan Notices 21, 12 ( 1986 ), 158-166.Google Scholar
- Sebastian Ullrich and Leonardo de Moura. 2019. Counting Immutable Beans: Reference Counting Optimized for Purely Functional Programming. arXiv preprint arXiv: 1908. 05647 ( 2019 ).Google Scholar
- The Univalent Foundations Program. 2013. Homotopy Type Theory: Univalent Foundations of Mathematics. https: //homotopytypetheory.org/book, Institute for Advanced Study.Google Scholar
- Philip Wadler. 1990. Comprehending monads. In Proceedings of the 1990 ACM conference on LISP and functional programming. 61-78.Google Scholar
Digital Library
- Philip Wadler and Stephen Blott. 1989. How to make ad-hoc polymorphism less ad hoc. In Proceedings of the 16th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. ACM, 60-76.Google Scholar
Digital Library
Index Terms
Sealing pointer-based optimizations behind pure functions
Recommendations
Reasoning about Object-based Calculi in (Co)Inductive Type Theory and the Theory of Contexts
AbstractWe illustrate a methodology for formalizing and reasoning about Abadi and Cardelli’s object-based calculi, in (co)inductive type theory, such as the Calculus of (Co)Inductive Constructions, by taking advantage of natural deduction semantics and ...
Reasoning on an imperative object-based calculus in Higher Order Abstract Syntax
MERLIN '03: Proceedings of the 2003 ACM SIGPLAN workshop on Mechanized reasoning about languages with variable bindingWe illustrate the benefits of using Natural Deduction in combination with weak Higher-Order Abstract Syntax for formalizing an object-based calculus with objects, cloning, method-update, types with subtyping, and side-effects, in inductive type theories ...
Completeness and Decidability Results for CTL in Constructive Type Theory
We prove completeness and decidability results for the temporal logic CTL in Coq/Ssreflect. Our main result is a constructive proof that for every formula one can obtain either a finite model satisfying the formula or a proof in a Hilbert system ...






Comments