System F in Agda, for Fun and Profit

  • James ChapmanEmail author
  • Roman Kireev
  • Chad Nester
  • Philip Wadler
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11825)


System F, also known as the polymorphic \(\lambda \)-calculus, is a typed \(\lambda \)-calculus independently discovered by the logician Jean-Yves Girard and the computer scientist John Reynolds. We consider \(F_{\omega \mu }\), which adds higher-order kinds and iso-recursive types. We present the first complete, intrinsically typed, executable, formalisation of System \(F_{\omega \mu }\) that we are aware of. The work is motivated by verifying the core language of a smart contract system based on System \(F_{\omega \mu }\). The paper is a literate Agda script [14].



We thank the anonymous reviewers for their helpful comments and insightful constructive criticism. We thank IOHK for their support of this work. We thank our colleagues Marko Dimjaević, Kenneth MacKenzie, and Michael Peyton Jones for helpful comments on an multiple drafts. The first author would like to James McKinna for spending an afternoon explaining pure type systems and Guillaume Allais, Apostolis Xekoukoulotakis and Ulf Norell for help with diagnosing and fixing bugs that we encountered in Agda’s GHC backend in the course of writing this paper.


  1. 1.
    Abadi, M., Cardelli, L., Plotkin, G.: Types for the Scott numerals (1993)Google Scholar
  2. 2.
    Allais, G., Chapman, J., McBride, C., McKinna, J.: Type-and-scope safe programs and their proofs. In: Bertot, Y., Vafeiadis, V. (eds.) Proceedings of the 6th ACM SIGPLAN Conference on Certified Programs and Proofs (CPP 2017), pp. 195–207. ACM, New York (2017).
  3. 3.
    Allais, G., McBride, C., Boutillier, P.: New equations for neutral terms. In: Weirich, S. (ed.) Proceedings of the 2013 ACM SIGPLAN Workshop on Dependently-typed Programming (DTP 2013), pp. 13–24. ACM, New York (2013).
  4. 4.
    Altenkirch, T., Chapman, J., Uustalu, T.: Relative monads formalised. J. Formalized Reasoning 7(1), 1–43 (2014). Scholar
  5. 5.
    Altenkirch, T., Chapman, J., Uustalu, T.: Monads need not be endofunctors. Logical Methods Comput. Sci. 11(1), 1–40 (2015). Scholar
  6. 6.
    Altenkirch, T., Reus, B.: Monadic presentations of lambda terms using generalized inductive types. In: Flum, J., Rodriguez-Artalejo, M. (eds.) CSL 1999. LNCS, vol. 1683, pp. 453–468. Springer, Heidelberg (1999). Scholar
  7. 7.
    Amani, S., Bégel, M., Bortin, M., Staples, M.: Towards verifying ethereum smart contract bytecode in isabelle/HOL. In: Andronick, J., Felty, A. (eds.) Proceedings of the 7th ACM SIGPLAN International Conference on Certified Programs and Proofs (CPP 2018), pp. 66–77. ACM, New York (2018).
  8. 8.
    Aydemir, B.E., et al.: Mechanized metatheory for the masses: the PoplMark challenge. In: Hurd, J., Melham, T. (eds.) TPHOLs 2005. LNCS, vol. 3603, pp. 50–65. Springer, Heidelberg (2005). Scholar
  9. 9.
    Berger, U., Schwichtenberg, H.: An inverse of the evaluation functional for typed lambda-calculus. In: Kahn, G. (ed.) Proceedings of the Sixth Annual Symposium on Logic in Computer Science (LICS 1991), pp. 203–211. IEEE Computer Society Press (1991).
  10. 10.
    Brown, M., Palsberg, J.: Breaking through the normalization barrier: a self-interpreter for F-omega. In: Majumdar, R. (ed.) Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, pp. 5–17. ACM, New York (2016).
  11. 11.
    Cai, Y., Giarrusso, P.G., Ostermann, K.: System F-omega with equirecursive types for datatype-generic programming. In: Majumdar, R. (ed.) Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2016), pp. 30–43. ACM, New York (2016).
  12. 12.
    Chakravarty, M., et al.: Functional Blockchain Contracts. Technical report, IOHK (2019).
  13. 13.
    Chapman, J.: Type checking and normalisation. Ph.D. thesis, University of Nottingham, UK (2009).
  14. 14.
    Chapman, J., Kireev, R., Nester, C., Wadler, P.: Literate Agda source of MPC 2019 paper (2019).
  15. 15.
    Coquand, C.: A formalised proof of the soundness and completeness of a simply typed lambda-calculus with explicit substitutions. High. Order Symbolic Comput. 15(1), 57–90 (2002). Scholar
  16. 16.
    Danielsson, N.A.: A formalisation of a dependently typed language as an inductive-recursive family. In: Altenkirch, T., McBride, C. (eds.) TYPES 2006. LNCS, vol. 4502, pp. 93–109. Springer, Heidelberg (2007). Scholar
  17. 17.
    van Doorn, F., Geuvers, H., Wiedijk, F.: Explicit convertibility proofs in pure type systems. In: Proceedings of the Eighth ACM SIGPLAN International Workshop on Logical Frameworks & Meta-languages: Theory & Practice, (LFMTP 2013), pp. 25–36. ACM, New York (2013).
  18. 18.
    Dreyer, D.: Understanding and Evolving the ML Module System. Ph.D. thesis, Carnegie Mellon University (2005)Google Scholar
  19. 19.
    Dreyer, D.: A type system for recursive modules. In: Ramsey, N. (ed.) Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming (ICFP 2007), pp. 289–302. ACM, New York (2007). Scholar
  20. 20.
    Dybjer, P.: A general formulation of simultaneous inductive-recursive definitions in type theory. J. Symbolic Logic 65(2), 525–549 (2000). Scholar
  21. 21.
    Grishchenko, I., Maffei, M., Schneidewind, C.: A semantic framework for the security analysis of ethereum smart contracts. In: Bauer, L., Küsters, R. (eds.) POST 2018. LNCS, vol. 10804, pp. 243–269. Springer, Cham (2018). Scholar
  22. 22.
    Harz, D., Knottenbelt, W.J.: Towards Safer Smart Contracts: A Survey of Languages and Verification Methods (2018).
  23. 23.
    Hindley, J.R., Seldin, J.P.: Lambda-Calculus and Combinators: An Introduction. Cambridge University Press, Cambridge (2008)Google Scholar
  24. 24.
    Hirai, Y.: Defining the ethereum virtual machine for interactive theorem provers. In: Brenner, M., et al. (eds.) FC 2017. LNCS, vol. 10323, pp. 520–535. Springer, Cham (2017). Scholar
  25. 25.
    Jung, A., Tiuryn, J.: A new characterization of lambda definability. In: Bezem, M., Groote, J.F. (eds.) TLCA 1993. LNCS, vol. 664, pp. 245–257. Springer, Heidelberg (1993). Scholar
  26. 26.
    Peyton Jones, M., Gkoumas, V., Kireev, R., MacKenzie, K., Nester, C., Wadler, P.: Unraveling recursion: compiling an IR with recursion to system F. In: Hutton, G. (ed.) MPC 2019. LNCS, vol. 11825, pp. 414–443. Springer, Cham (2019). Scholar
  27. 27.
  28. 28.
    Martens, C., Crary, K.: LF in LF: mechanizing the metatheories of LF in Twelf. In: Proceedings of the Seventh International Workshop on Logical Frameworks and Meta-languages, Theory and Practice (LFMTP 2012), pp. 23–32. ACM, New York (2012).
  29. 29.
    McBride, C.: Datatypes of datatypes. In: Summer School on Generic and Effectful Programming, St Anne’s College, Oxford (2015).
  30. 30.
    Nomadic Labs: Michelson in Coq. Git Repository.
  31. 31.
    O’Connor, R.: Simplicity: a new language for blockchains. In: Bielova, N., Gaboardi, M. (eds.) Proceedings of the 2017 Workshop on Programming Languages and Analysis for Security (PLAS 2017), pp. 107–120. ACM, New York (2017).
  32. 32.
    Park, D., Zhang, Y., Saxena, M., Daian, P., Roşu, G.: A formal verification tool for ethereum VM bytecode. In: Garcia, A., Pasareanu, C.S. (eds.) Proceedings of the 2018 26th ACM Join Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering (ESEC/FSE 2018), pp. 912–915. ACM, New York (2018).
  33. 33.
    Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)Google Scholar
  34. 34.
    Pollack, R., Poll, E.: Typechecking in pure type systems. In: Informal Proceedings of Logical Frameworks 1992, pp. 271–288 (1992)Google Scholar
  35. 35.
    Reynolds, J.C.: What do types mean? - from intrinsic to extrinsic semantics. In: McIver, A., Morgan, C. (eds.) Programming Methodology. Monographs in Computer Science, pp. 309–327. Springer, New York (2003). Scholar
  36. 36.
    Wadler, P.: Programming language foundations in agda. In: Massoni, T., Mousavi, M.R. (eds.) SBMF 2018. LNCS, vol. 11254, pp. 56–73. Springer, Cham (2018). Scholar
  37. 37.
    Wadler, P., Kokke, W.: Programming Language Foundations in Agda.
  38. 38.
    Watkins, K., Cervesato, I., Pfenning, F., Walker, D.: Specifying properties of concurrent computations in CLF. In: Schürmann, C. (ed.) Proceedings of the Fourth International Workshop on Logical Frameworks and Meta-Languages (LFM 2004). ENTCS, vol. 199, pp. 67–87 (2008). Scholar

Copyright information

© Springer Nature Switzerland AG 2019

Authors and Affiliations

  1. 1.IOHKHong KongHong Kong
  2. 2.University of EdinburghEdinburghUK

Personalised recommendations