skip to main content
research-article
Open Access

No-brainer CPS conversion (functional pearl)

Published:29 August 2017Publication History
Skip Abstract Section

Abstract

Algorithms that convert direct-style λ-calculus terms to their equivalent terms in continuation-passing style (CPS) typically introduce so-called “administrative redexes:” useless artifacts of the conversion that must be cleaned up by a subsequent pass over the result to reduce them away. We present a simple, linear-time algorithm for CPS conversion that introduces no administrative redexes. In fact, the output term is a normal form in a reduction system that generalizes the notion of “administrative redexes” to what we call “no-brainer redexes,” that is, redexes whose reduction shrinks the size of the term. We state the theorems which establish the algorithm's desireable properties, along with sketches of the full proofs.

References

  1. Andrew W. Appel. 2006. Compiling with Continuations. Cambridge University Press.Google ScholarGoogle Scholar
  2. Andrew W. Appel and Trevor Jim. 1997. Shrinking lambda expressions in linear time. Journal of Functional Programming 7, 5 (1997), 515–540. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Hendrik Pieter Barendregt. 1985. The Lambda Calculus: Its Syntax and Semantics. Studies in Logic and the Foundations of Mathematics, Vol. 103. North-Holland, Amsterdam.Google ScholarGoogle Scholar
  4. Richard Bird and Philip Wadler. 1992. Introduction to Functional Programming. Prentice Hall.Google ScholarGoogle Scholar
  5. Olivier Danvy. 2008. Defunctionalized interpreters for programming languages. In Proceeding of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP) (SIGPLAN Notices, Vol. 43, No. 9). 131–142. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Olivier Danvy and Andrzej Filinski. 1992. Representing control: A study of the CPS transformation. Mathematical Structures in Computer Science 2, 4 (1992), 361–391. Google ScholarGoogle ScholarCross RefCross Ref
  7. Michael J. Fischer. 1993. Lambda-calculus schemata. LISP and Symbolic Computation 6, 3/4 (1993), 259–288. Earlier version originally published in Proceedings of the ACM Conference on Proving Assertions about Programs, SIGPLAN Notices, Vol. 7, No. 1, and SIGACT News, No. 14, 104–109 ( January 1972).Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The essence of compiling with continuations. In Proceedings of the ACM SIGPLAN’93 Conference on Programming Language Design and Implementation (PLDI) (ACM SIGPLAN Notices, Vol. 28, No. 6). 237–247. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Matt Kaufmann, Panagiotis Manolios, and J Strother Moore. 1990. Computer-Aided Reasoning: An Approach. Number 3 in Advances in Formal Methods. Kluwer Academic Publishers.Google ScholarGoogle Scholar
  10. Richard A. Kelsey. 1989. Compilation by Program Transformation. Ph.D. Dissertation. Computer Science Department, Yale University, New Haven, Connecticut. Research Report 702.Google ScholarGoogle Scholar
  11. Richard A. Kelsey. 1995. A correspondence between continuation passing style and static single assignment form. In ACM SIGPLAN Workshop on Intermediate Representations (SIGPLAN Notices, Vol. 30, No. 3). 13–22. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Richard A. Kelsey and Paul Hudak. 1989. Realistic compilation by program transformation. In Proceedings of the Sixteenth Annual ACM Symposium on Principles of Programming Languages (POPL). 281–292. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Andrew Kennedy. 2007. Compiling with continuations, continued. In Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming (ICFP) (ACM SIGPLAN Notices, Vol. 42, No. 9). 177–190. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. David Kranz, Richard Kelsey, Jonathan Rees, Paul Hudak, James Philbin, and Norman Adams. 1986. ORBIT: An optimizing compiler for Scheme. In Proceedings of the 1986 SIGPLAN Symposium on Compiler Construction (SIGPLAN Notices, Vol. 21, No. 7). 219–233. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. David A. Kranz. 1988. ORBIT: An Optimizing Compiler for Scheme. Ph.D. Dissertation. Computer Science Department, Yale University, New Haven, Connecticut. Research Report 632.Google ScholarGoogle Scholar
  16. Kevin Millikin. 2005. A new approach to one-pass transformations. In Trends in Functional Programming Volume 6. Intellect Books, 252–264.Google ScholarGoogle Scholar
  17. Gordon D. Plotkin. 1975. Call-by-name, call-by-value and the λ-calculus. Theoretical Computer Science 1, 2 (Dec. 1975), 125–159. Google ScholarGoogle ScholarCross RefCross Ref
  18. Brian Rabern. 2016. The history of the use of · -notation in natural language semantics. Semantics and Pragmatics 9 (2016), 1–10. Google ScholarGoogle ScholarCross RefCross Ref
  19. John C. Reynolds. 1972. Definitional interpreters for higher-order programming languages. In Proceedings of 25th National ACM Conference. 717–740. Reprinted in LISP and Symbolic Computation, 11 363–397 (1998).Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. John C. Reynolds. 1993. The discoveries of continuations. LISP and Symbolic Computation 6, 3/4 (Dec. 1993), 233–247. Special Issue on Continuations (Part I). Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Amr Sabry and Matthias Felleisen. 1993. Reasoning about programs in continuation-passing style. LISP and Symbolic Computation 6, 3/4 (Dec. 1993), 289–360. Special Issue on Continuations (Part I). Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Olin Shivers and David Fisher. 2006. Multi-return function call. Journal of Functional Programming 16, 4/5 (July/September 2006), 547–582. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Guy L. Steele Jr. 1976. Lambda, the ultimate declarative. AI Memo 379. Artificial Intelligence Laboratory, Massachusetts Institute of Technology, Cambridge, Massachusetts.Google ScholarGoogle Scholar
  24. Guy L. Steele Jr. 1978. RABBIT: A Compiler for SCHEME. Master’s thesis. Artificial Intelligence Laboratory, Massachusetts Institute of Technology, Cambridge, Massachusetts. Technical report AI-TR-474.Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. No-brainer CPS conversion (functional pearl)

          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!