Abstract
In call-by-value languages, some mutually-recursive definitions can be safely evaluated to build recursive functions or cyclic data structures, but some definitions (let rec x = x + 1) contain vicious circles and their evaluation fails at runtime. We propose a new static analysis to check the absence of such runtime failures.
We present a set of declarative inference rules, prove its soundness with respect to the reference source-level semantics of Nordlander, Carlsson, and Gill [2008], and show that it can be directed into an algorithmic backwards analysis check in a surprisingly simple way.
Our implementation of this new check replaced the existing check used by the OCaml programming language, a fragile syntactic criterion which let several subtle bugs slip through as the language kept evolving. We document some issues that arise when advanced features of a real-world functional language (exceptions in first-class modules, GADTs, etc.) interact with safety checking for recursive definitions.
- Andreas Abel and Jean-Philippe Bernardy. 2020. A Unified View of Modalities in Type Systems. In ICFP.Google Scholar
- Beniamino Accattoli. 2013. Evaluating functions as processes. In TERMGRAPH.Google Scholar
- Beniamino Accattoli and Delia Kesner. 2010. The structural lambda-calculus. (Oct. 2010 ). working paper or preprint.Google Scholar
- Zena M. Ariola and Matthias Felleisen. 1997. The Call-By-Need lambda Calculus. J. Funct. Program. 7, 3 ( 1997 ), 265-301.Google Scholar
Digital Library
- Romain Bardou. 2005. Typage des modules récursifs en Caml. Technical Report. ENS Lyon.Google Scholar
- Gérard Boudol. 2001. The Recursive Record Semantics of Objects Revisited. In Programming Languages and Systems. Springer Berlin Heidelberg, Berlin, Heidelberg, 269-283.Google Scholar
- Gérard Boudol and Pascal Zimmer. 2002. Recursion in the call-by-value lambda-calculus. In FICS. 61-66.Google Scholar
- Frédéric Bour, Thomas Refis, and Gabriel Scherer. 2018. Merlin: a language server for OCaml (experience report). PACMPL 2, ICFP ( 2018 ).Google Scholar
- Stephen Chang and Matthias Felleisen. 2012. The Call-by-Need Lambda Calculus, Revisited. In ESOP (Lecture Notes in Computer Science, Vol. 7211 ), Helmut Seidl (Ed.). Springer, 128-147.Google Scholar
- Derek Dreyer. 2004. A Type System for Well-founded Recursion. In POPL. ACM, New York, NY, USA, 293-305.Google Scholar
- Matthias Felleisen and Robert Hieb. 1992. The Revised Report on the Syntactic Theories of Sequential Control and State. Theor. Comput. Sci. 103, 2 ( 1992 ), 235-271.Google Scholar
- Jacques Garrigue and Didier Rémy. 2013. Ambivalent Types for Principal Type Inference with GADTs. In APLAS. 257-272.Google Scholar
- Samir Genaim and Michael Codish. 2001. Inferring termination conditions for logic programs using backwards analysis. In APPIA-GULP-PRODE 2001: Joint Conference on Declarative Programming, Évora, Portgual, September 26-28, 2001, Proceedings, Évora, Portugal, September 26-28, 2001, Luís Moniz Pereira and Paulo Quaresma (Eds.). Departamento de Informática, Universidade de Évora, 229-243.Google Scholar
- Abdulaziz Ghuloum and R. Kent Dybvig. 2009. Fixing Letrec (reloaded). In Scheme Workshop.Google Scholar
- Tom Hirschowitz and Sergueï Lenglet. 2005. A practical type system for generalized recursion. Technical Report. ENS Lyon.Google Scholar
- Tom Hirschowitz, Xavier Leroy, and J. B. Wells. 2003. Compilation of Extended Recursion in Call-by-value Functional Languages. In PPDP. ACM, New York, NY, USA, 160-171.Google Scholar
- Tom Hirschowitz, Xavier Leroy, and J. B. Wells. 2009. Compilation of Extended Recursion in Call-by-value Functional Languages. Higher Order Symbol. Comput. 22, 1 (March 2009 ).Google Scholar
Digital Library
- John Hughes. 1987. Backwards Analysis of Functional Programs. In Partial Evaluation and Mixed Computation.Google Scholar
- Jean-Baptiste Jeannin, Dexter Kozen, and Alexandra Silva. 2017. CoCaml: Functional Programming with Regular Coinductive Types. Fundamenta Informaticae 150 ( 2017 ), 347-377.Google Scholar
- Oleg Kiselyov. 2014. The Design and Implementation of BER MetaOCaml-System Description. In FLOPS. 86-102.Google Scholar
- John Launchbury. 1993. A Natural Semantics for Lazy Evaluation. In POPL, Mary S. Van Deusen and Bernard Lang (Eds.). ACM Press, 144-154.Google Scholar
- Robin Milner, Mads Tofte, and David Macqueen. 1997. The Definition of Standard ML. MIT Press, Cambridge, MA, USA.Google Scholar
Digital Library
- Johan Nordlander, Magnus Carlsson, and Andy J. Gill. 2008. Unrestricted Pure Call-by-value Recursion. In ML Workshop.Google Scholar
- Ilya Sergey, Simon Peyton-Jones, and Dimitrios Vytiniotis. 2017a. Theory and Practice of Demand Analysis in Haskell. draft.Google Scholar
- Ilya Sergey, Dimitrios Vytiniotis, Simon L. Peyton Jones, and Joachim Breitner. 2017b. Modular, higher order cardinality analysis in theory and practice. J. Funct. Program. 27 ( 2017 ), e11.Google Scholar
- Michael Sperber, R. Kent Dybvig, Matthew Flatt, Anton Van Straaten, Robby Findler, and Jacob Matthews. 2009. Revised6 Report on the Algorithmic Language Scheme. Journal of Functional Programming 19, S1 ( 2009 ), 1-301.Google Scholar
Digital Library
- Don Syme. 2005. An Alternative Approach to Initializing Mutually Referential Objects. Technical Report MSR-TR-2005-31. 27 pages.Google Scholar
- Don Syme. 2006. Initializing Mutually Referential Abstract Objects: The Value Recursion Challenge. Electron. Notes Theor. Comput. Sci. 148, 2 ( 2006 ), 3-25.Google Scholar
- Don Syme. 2012. The Fsharp language reference, Versions 2.0 to 4.1, Section 14.6.6, Recursive Safety Analysis.Google Scholar
- Oscar Waddell, Dipanwita Sarkar, and R. Kent Dybving. 2005. Fixing Letrec: A Faithful Yet Eficient Implementation of Scheme's Recursive Binding Construct. Journal of Higher-Order and Symbolic Computation 18 ( 2005 ).Google Scholar
Index Terms
A practical mode system for recursive definitions
Recommendations
Programs Using Syntax with First-Class Binders
Programming Languages and SystemsAbstractWe present a general methodology for adding support for higher-order abstract syntax definitions and first-class contexts to an existing ML-like language. As a consequence, low-level infrastructure that deals with representing variables and ...
A Language Designer's Workbench: A One-Stop-Shop for Implementation and Verification of Language Designs
Onward! 2014: Proceedings of the 2014 ACM International Symposium on New Ideas, New Paradigms, and Reflections on Programming & SoftwareThe realization of a language design requires multiple artifacts that redundantly encode the same information. This entails significant effort for language implementors, and often results in late detection of errors in language definitions. In this ...
ML: metalanguage or object language?
ICFP '10My talk will celebrate Robin Milner's contribution to functional programming via a combination of reminiscences about the early days of ML and speculations about its future.






Comments