Programming Language Foundations in Agda
One of the leading textbooks for formal methods is Software Foundations (SF), written by Benjamin Pierce in collaboration with others, and based on Coq. After five years using SF in the classroom, I have come to the conclusion that Coq is not the best vehicle for this purpose, as too much of the course needs to focus on learning tactics for proof derivation, to the cost of learning programming language theory. Accordingly, I have written a new textbook, Programming Language Foundations in Agda (PLFA). PLFA covers much of the same ground as SF, although it is not a slavish imitation.
What did I learn from writing PLFA? First, that it is possible. One might expect that without proof tactics that the proofs become too long, but in fact proofs in PLFA are about the same length as those in SF. Proofs in Coq require an interactive environment to be understood, while proofs in Agda can be read on the page. Second, that constructive proofs of preservation and progress give immediate rise to a prototype evaluator. This fact is obvious in retrospect but it is not exploited in SF (which instead provides a separate normalise tactic) nor can I find it in the literature. Third, that using raw terms with a separate typing relation is far less perspicuous than using inherently-typed terms. SF uses the former presentation, while PLFA presents both; the former uses about 1.6 as many lines of Agda code as the latter, roughly the golden ratio.
The textbook is written as a literate Agda script, and can be found here: http://plfa.inf.ed.ac.uk.
KeywordsAgda Coq Lambda calculus Dependent types
A special thank you to my coauthor, Wen Kokke. For inventing ideas on which PLFA is based, and for hand-holding, many thanks to Conor McBride, James McKinna, Ulf Norell, and Andreas Abel. For showing me how much more compact it is to avoid raw terms, thanks to David Darais. For inspiring my work by writing SF, thanks to Benjamin Pierce and his coauthors. For comments on a draft of this paper, an extra thank you to James McKinna, Ulf Norell, Andreas Abel, and Benjamin Pierce. This research was supported by EPSRC Programme Grant EP/K034413/1.
- Allais, G., Chapman, J., McBride, C., McKinna, J.: Type-and-scope safe programs and their proofs. In: Proceedings of the 6th ACM SIGPLAN Conference on Certified Programs and Proofs, pp. 195–207. ACM (2017)Google Scholar
- Bove, A., Dybjer, P., Norell, U.: A brief overview of agda – a functional language with dependent types. In: Berghofer, S., Nipkow, T., Urban, C., Wenzel, M. (eds.) TPHOLs 2009. LNCS, vol. 5674, pp. 73–78. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-03359-9_6CrossRefGoogle Scholar
- Capretta, V.: General recursion via coinductive types. Log. Methods Comput. Sci. 1(2:1), 1–28 (2005)Google Scholar
- Chapman, J.M.: Type checking and normalisation. PhD thesis, University of Nottingham (2009)Google Scholar
- Dagand, P.-É., Scherer, G.: Normalization by realizability also evaluates. In: Vingt-sixièmes Journées Francophones des Langages Applicatifs (JFLA 2015) (2015)Google Scholar
- Felleisen, M., Findler, R.B., Flatt, M.: Semantics engineering with PLT Redex. By Press (2009)Google Scholar
- Goguen, H., McKinna, J.: Candidates for substitution. Technical report, Laboratory for Foundations of Computer Science, University of Edinburgh (1997)Google Scholar
- Hales, T., et al.: A formal proof of the Kepler conjecture. In: Forum of Mathematics, Pi, vol. 5. Cambridge University Press (2017)Google Scholar
- Harper, R.: Practical Foundations for Programming Languages. Cambridge University Press (2016)Google Scholar
- Huet, G., Kahn, G., Paulin-Mohring, C.: The Coq proof assistant a tutorial. Rapport Technique, 178 (1997)Google Scholar
- Kästner, D., Leroy, X., Blazy, S., Schommer, B., Schmidt, M., Ferdinand, C.: Closing the gap-the formally verified optimizing compiler compcert. In: SSS 2017: Safety-critical Systems Symposium 2017, pp. 163–180. CreateSpace (2017)Google Scholar
- Kiselyov, O.: Formalizing languages, mechanizing type-soundess and other meta-theoretic proofs (2009, unpublished manuscript). http://okmij.org/ftp/formalizations/index.html
- Klein, G., et al.: sel4: formal verification of an OS kernel. In: Proceedings of the ACM SIGOPS 22nd Symposium on Operating Systems Principles, pp. 207–220. ACM (2009)Google Scholar
- McBride, C.: Type-preserving renaming and substitution (2005, unpublished manuscript). https://personal.cis.strath.ac.uk/conor.mcbride/ren-sub.pdf
- O’Connor, L., et al.: Refinement through restraint: Bringing down the cost of verification. In: ICFP, pp. 89–102 (2016)Google Scholar
- Pierce, B.C.: Types and Programming Languages. MIT press (2002)Google Scholar
- Pierce, B.C.: Lambda, the ultimate TA. In: ICFP, pp. 121–122 (2009)Google Scholar
- Pierce, B.C.: Software foundations (2010). http://www.cis.upenn.edu/bcpierce/sf/current/index.html
- Stump, A.: Verified Functional Programming in Agda. Morgan & Claypool (2016)Google Scholar