skip to main content

A practical mode system for recursive definitions

Published:04 January 2021Publication History
Skip Abstract Section

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.

References

  1. Andreas Abel and Jean-Philippe Bernardy. 2020. A Unified View of Modalities in Type Systems. In ICFP.Google ScholarGoogle Scholar
  2. Beniamino Accattoli. 2013. Evaluating functions as processes. In TERMGRAPH.Google ScholarGoogle Scholar
  3. Beniamino Accattoli and Delia Kesner. 2010. The structural lambda-calculus. (Oct. 2010 ). working paper or preprint.Google ScholarGoogle Scholar
  4. Zena M. Ariola and Matthias Felleisen. 1997. The Call-By-Need lambda Calculus. J. Funct. Program. 7, 3 ( 1997 ), 265-301.Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Romain Bardou. 2005. Typage des modules récursifs en Caml. Technical Report. ENS Lyon.Google ScholarGoogle Scholar
  6. Gérard Boudol. 2001. The Recursive Record Semantics of Objects Revisited. In Programming Languages and Systems. Springer Berlin Heidelberg, Berlin, Heidelberg, 269-283.Google ScholarGoogle Scholar
  7. Gérard Boudol and Pascal Zimmer. 2002. Recursion in the call-by-value lambda-calculus. In FICS. 61-66.Google ScholarGoogle Scholar
  8. Frédéric Bour, Thomas Refis, and Gabriel Scherer. 2018. Merlin: a language server for OCaml (experience report). PACMPL 2, ICFP ( 2018 ).Google ScholarGoogle Scholar
  9. 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 ScholarGoogle Scholar
  10. Derek Dreyer. 2004. A Type System for Well-founded Recursion. In POPL. ACM, New York, NY, USA, 293-305.Google ScholarGoogle Scholar
  11. 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 ScholarGoogle Scholar
  12. Jacques Garrigue and Didier Rémy. 2013. Ambivalent Types for Principal Type Inference with GADTs. In APLAS. 257-272.Google ScholarGoogle Scholar
  13. 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 ScholarGoogle Scholar
  14. Abdulaziz Ghuloum and R. Kent Dybvig. 2009. Fixing Letrec (reloaded). In Scheme Workshop.Google ScholarGoogle Scholar
  15. Tom Hirschowitz and Sergueï Lenglet. 2005. A practical type system for generalized recursion. Technical Report. ENS Lyon.Google ScholarGoogle Scholar
  16. 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 ScholarGoogle Scholar
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. John Hughes. 1987. Backwards Analysis of Functional Programs. In Partial Evaluation and Mixed Computation.Google ScholarGoogle Scholar
  19. Jean-Baptiste Jeannin, Dexter Kozen, and Alexandra Silva. 2017. CoCaml: Functional Programming with Regular Coinductive Types. Fundamenta Informaticae 150 ( 2017 ), 347-377.Google ScholarGoogle Scholar
  20. Oleg Kiselyov. 2014. The Design and Implementation of BER MetaOCaml-System Description. In FLOPS. 86-102.Google ScholarGoogle Scholar
  21. John Launchbury. 1993. A Natural Semantics for Lazy Evaluation. In POPL, Mary S. Van Deusen and Bernard Lang (Eds.). ACM Press, 144-154.Google ScholarGoogle Scholar
  22. Robin Milner, Mads Tofte, and David Macqueen. 1997. The Definition of Standard ML. MIT Press, Cambridge, MA, USA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Johan Nordlander, Magnus Carlsson, and Andy J. Gill. 2008. Unrestricted Pure Call-by-value Recursion. In ML Workshop.Google ScholarGoogle Scholar
  24. Ilya Sergey, Simon Peyton-Jones, and Dimitrios Vytiniotis. 2017a. Theory and Practice of Demand Analysis in Haskell. draft.Google ScholarGoogle Scholar
  25. 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 ScholarGoogle Scholar
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. Don Syme. 2005. An Alternative Approach to Initializing Mutually Referential Objects. Technical Report MSR-TR-2005-31. 27 pages.Google ScholarGoogle Scholar
  28. Don Syme. 2006. Initializing Mutually Referential Abstract Objects: The Value Recursion Challenge. Electron. Notes Theor. Comput. Sci. 148, 2 ( 2006 ), 3-25.Google ScholarGoogle Scholar
  29. Don Syme. 2012. The Fsharp language reference, Versions 2.0 to 4.1, Section 14.6.6, Recursive Safety Analysis.Google ScholarGoogle Scholar
  30. 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 ScholarGoogle Scholar

Index Terms

  1. A practical mode system for recursive definitions

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!