skip to main content
10.1145/964001.964009acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
Article

Polymorphic typed defunctionalization

Published:01 January 2004Publication History

ABSTRACT

Defunctionalization is a program transformation that aims to turn a higher-order functional program into a first-order one, that is, to eliminate the use of functions as first-class values. Its purpose is thus identical to that of closure conversion. It differs from closure conversion, however, by storing a tag, instead of a code pointer, within every closure. Defunctionalization has been used both as a reasoning tool and as a compilation technique.Defunctionalization is commonly defined and studied in the setting of a simply-typed λ-calculus, where it is shown that semantics and well-typedness are preserved. It has been observed that, in the setting of a polymorphic type system, such as ML or System F, defunctionalization is not type-preserving. In this paper, we show that extending System F with guarded algebraic data types allows recovering type preservation. This result allows adding defunctionalization to the toolbox of type-preserving compiler writers.

References

  1. Anindya Banerjee, Nevin Heintze, and Jon G. Riecke. Design and correctness of program transformations based on control-flow analysis. In International Symposium on Theoretical Aspects of Computer Software (TACS), volume 2215 of Lecture Notes in Computer Science, pages 420--447. Springer Verlag, October 2001. http://www.cis.ksu.edu/~ab/Publications/pcfa.ps.gz.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Jeffrey M. Bell, Françoise Bellegarde, and James Hook. Type-driven defunctionalization. In ACM International Conference on Functional Programming (ICFP), August 1997. http://doi.acm.org/10.1145/258949.258953.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Henry Cejtin, Suresh Jagannathan, and Stephen Weeks. Flow-directed closure conversion for typed languages. In European Symposium on Programming (ESOP), volume 1782 of Lecture Notes in Computer Science, pages 56--71. Springer Verlag, March 2000. http://www.mlton.org/papers/00-esop.ps.gz.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. James Cheney and Ralf Hinze. First-class phantom types. Technical Report 1901, Cornell University, 2003. http://techreports.library.cornell.edu:8081/Dienst/UI/1.0/Display/cul.cis/TR2003-1901.]]Google ScholarGoogle Scholar
  5. Olivier Danvy. Functional unparsing. Journal of Functional Programming, 8(6):621--625, November 1998.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Olivier Danvy and Lasse R. Nielsen. Defunctionalization at work. In ACM International Conference on Principles and Practice of Declarative Programming (PPDP), pages 162--174, September 2001.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. The essence of compiling with continuations. In ACM Conference on Programming Language Design and Implementation (PLDI), pages 237--247, 1993. http://www.cs.rice.edu/CS/PLT/Publications/Scheme/pldi93-fsdf.ps.gz.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Yasuhiko Minamide, Greg Morrisett, and Robert Harper. Typed closure conversion. In ACM Symposium on Principles of Programming Languages (POPL), pages 271--283, January 1996. http://www.cs.cornell.edu/Info/People/jgm/papers/closure-summary.ps.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Greg Morrisett and Robert Harper. Typed closure conversion for recursively-defined functions (extended abstract). In International Workshop on Higher Order Operational Techniques in Semantics (HOOTS), volume 10 of Electronic Notes in Theoretical Computer Science. Elsevier Science, 1998. http://www.cs.cornell.edu/home/jgm/papers/hootsclosure.ps.]]Google ScholarGoogle Scholar
  10. Greg Morrisett, David Walker, Karl Crary, and Neal Glew. From system F to typed assembly language. ACM Transactions on Programming Languages and Systems, 21(3):528--569, May 1999. http://www.cs.cornell.edu/talc/papers/tal-toplas.pdf.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Lasse R. Nielsen. A denotational investigation of defunctionalization. Technical Report RS-00-47, BRICS, December 2000. http://www.brics.dk/RS/00/47/.]]Google ScholarGoogle Scholar
  12. Christine Paulin-Mohring. Inductive definitions in the system coq: Rules and properties. Research Report RR1992-49, ENS Lyon, 1992. ftp://ftp.ens-lyon.fr/pub/LIP/Rapports/RR/RR1992/RR1992-49.ps.Z.]]Google ScholarGoogle Scholar
  13. John C. Reynolds. Definitional interpreters for higher-order programming languages. Higher-Order and Symbolic Computation, 11(4):363--397, December 1998. ftp://ftp.cs.cmu.edu/user/jcr/defint.dvi.gz.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. John C. Reynolds. Definitional interpreters revisited. Higher-Order and Symbolic Computation, 11(4):355--361, December 1998. ftp://ftp.cs.cmu.edu/user/jcr/defintintro.dvi.gz.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Andrew Tolmach. Combining closure conversion with closure analysis using algebraic types. In Workshop on Types in Compilation (TIC), June 1997. http://www.cs.pdx.edu/~apt/tic97.ps.]]Google ScholarGoogle Scholar
  16. Andrew Tolmach and Dino P. Oliva. From ML to Ada: Strongly-typed language interoperability via source translation. Journal of Functional Programming, 8(4):367--412, July 1998. http://www.cs.pdx.edu/~apt/jfp98.ps.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Hongwei Xi. Dead code elimination through dependent types. In International Workshop on Practical Aspects of Declarative Languages (PADL), volume 1551 of Lecture Notes in Computer Science, pages 228--242. Springer Verlag, January 1999. http://www.cs.bu.edu/~hwxi/academic/papers/padl99.ps.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Hongwei Xi, Chiyan Chen, and Gang Chen. Guarded recursive datatype constructors. In ACM Symposium on Principles of Programming Languages (POPL), January 2003. http://www.cs.bu.edu/fac/hwxi/academic/papers/popl03.ps.]] Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Polymorphic typed defunctionalization

          Recommendations

          Reviews

          Michael G. Murphy

          The issue of defunctionalization with type preservation is addressed in this paper. Defunctionalization is a program transformation that turns a higher-order functional program into a first-order functional program (with no functions as first-order values). The purpose of this transformation is similar to that of closure conversion, but it differs by storing a tag instead of a code pointer within every closure. Defunctionalization serves both as a reasoning tool and as a compilation technique. Defunctionalization is defined and studied most commonly in the setting of a simply typed lambda-calculus, where semantics and well typedness are preserved. With polymorphic type systems, as in ML or System F, defunctionalization is not type-preserving. The authors extend System F with guarded algebraic data types to preserve types. The problem with defining defunctionalization for a typed-polymorphic lambda-calculus lies in the definition of "apply" that simulates the application of a source function to a source value, then returning its result. The main contribution of this paper is its proof that defunctionalization may be viewed as a type-preserving transformation from System F, as extended with guarded algebraic data types, into itself. Also noted is a similar process that can be applied to ML. Another contribution of this paper is its proof that the transformation is meaning-preserving in an untyped setting; this result can then be lifted to the typed setting. After a carefully prepared introduction, the second section defines the extension of System F with guarded algebraic data types. The third section defines the defunctionalization of well-typed programs, and the fourth section includes a proof that defunctionalization of untyped programs preserves well typedness. The fifth section defines the defunctionalization of untyped programs, and includes a proof of meaning preservation, which also carries over to typed programs. The last section contains closing remarks. The authors' version of defunctionalization does not address optimization or a sophisticated treatment of multiple-argument functions, but it does broaden the case for defunctionalization as a compilation technique, and as a tool to help programmers transform programs and reason about them. The paper is rigorous, well written, and includes sufficient detail to satisfy functional language theorists. Online Computing Reviews Service

          Access critical reviews of Computing literature here

          Become a reviewer for Computing Reviews.

          Comments

          Login options

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

          Sign in
          • Published in

            cover image ACM Conferences
            POPL '04: Proceedings of the 31st ACM SIGPLAN-SIGACT symposium on Principles of programming languages
            January 2004
            364 pages
            ISBN:158113729X
            DOI:10.1145/964001
            • cover image ACM SIGPLAN Notices
              ACM SIGPLAN Notices  Volume 39, Issue 1
              POPL '04
              January 2004
              352 pages
              ISSN:0362-1340
              EISSN:1558-1160
              DOI:10.1145/982962
              Issue’s Table of Contents

            Copyright © 2004 ACM

            Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 1 January 2004

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • Article

            Acceptance Rates

            POPL '04 Paper Acceptance Rate29of176submissions,16%Overall Acceptance Rate824of4,130submissions,20%

            Upcoming Conference

            POPL '25

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader