Skip to main content
Log in

The Second Futamura Projection for Type-Directed Partial Evaluation

  • Published:
Higher-Order and Symbolic Computation

Abstract

A generating extension of a program specializes the program with respect to part of the input. Applying a partial evaluator to the program trivially yields a generating extension, but specializing the partial evaluator with respect to the program often yields a more efficient one. This specialization can be carried out by the partial evaluator itself; in this case, the process is known as the second Futamura projection.

We derive an ML implementation of the second Futamura projection for Type-Directed Partial Evaluation (TDPE). Due to the differences between ‘traditional’, syntax-directed partial evaluation and TDPE, this derivation involves several conceptual and technical steps. These include a suitable formulation of the second Futamura projection and techniques for making TDPE amenable to self-application. In the context of the second Futamura projection, we also compare and relate TDPE with conventional off-line partial evaluation.

We demonstrate our technique with several examples, including compiler generation for Tiny, a prototypical imperative language.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Berger, U. and Schwichtenberg, H. An inverse of the evaluation functional for typed λ-calculus. In Proceedings of the 6th Annual IEEE Symposium on Logic in Computer Science, A.R. Meyer (Ed.), Amsterdam, The Netherland, 1991, pp. 203–213.

    Google Scholar 

  2. Birkedal, L. and Welinder,M. Hand-writing program generator generators. In Sixth International Symposium on Programming Language Implementation and Logic Programming, Madrid, Spain, M. Hermenegildo and J. Penjam (Eds.), Lecture Notes in Computer Science, no. 844, Springer-Verlag, 1994, pp. 198–214.

  3. Bondorf, A. and Danvy, O. Automatic autoprojection of recursive equations with global variables and abstract data types. Science of Computer Programming, 16 (1991) 151–195.

    Google Scholar 

  4. Danvy, O. Pragmatic aspects of type-directed partial evaluation. In Partial Evaluation, Proceedings, O. Danvy, R. Glück, and P. Thiemann (Eds.), Lecture Notes in Computer Science, no. 1110, Springer-Varlag, 1996, pp. 73–94.

  5. Danvy, O. Type-directed partial evaluation. In Proceedings of the Twenty-Third Annual ACM Symposium on Principles of Programming Languages, G.L. Steele Jr. (Ed.), St. Petersburg Beach, Florida, 1996, pp. 242–257.

  6. Danvy. O. A simple solution to type specialization. In Proceedings of ICALP'98, Aalborg, Denmark, K.G. Larsen, S. Skyum, and G.Winskel (Eds.). Lecture Notes in Computer Science, no. 1443, Springer-Verlag, 1998, pp. 908–917.

  7. Danvy, O. Type-directed partial evaluation. In Partial Evaluation-Practice and Theory; Proceedings of the 1998 DIKU Summer School, Copenhagen, Denmark, Lecture Notes in Computer Science, no. 1706, Springer-Verlag, 1998, pp. 367–411. Extended version available as BRICS Technical Report LN–98–3.

  8. Danvy, O. and Dybjer, P. (Eds.). In Proceedings of the 1998 APPSEM Workshop on Normalization by Evaluation, NBE'98, Gothenburg, Sweden, May 8–9 1998. No. NS–98–8 in Note Series. Department of Computer Science, BRICS, University of Aarhus.

  9. Danvy, O. and Filinski, A. Representing control, a study of the CPS transformation. Mathematical Structures in Computer Science, 2(4), (1992) 361–391.

    Google Scholar 

  10. Danvy, O., Malmkjaer, K., and Palsberg J. Eta-expansion does The Trick. ACM Transactions on Programming Languages and Systems, 8(6) (1996) 730–751.

    Google Scholar 

  11. Danvy, O. and Rhiger, M. Compiling actions by partial evaluation, revisited. Technical Report BRICS-RS–98–13, BRICS, Department of Computer Science, University of Aarhus, 1998.

  12. Danvy, O. and Vestergaard, R. Semantics-based compiling: A case study in type-directed partial evaluation. In Eighth International Symposium on Programming Language Implementation and Logic Programming, H. Kuchen and D. Swierstra (Eds.), Aachen, Germany, 1996, pp. 182–197. Extended version available as BRICS Technical Report RS–96–13.

  13. Danvy, O. and Yang, Z. An operational investigation of the CPS hierarchy. In Proceedings of the Eighth European Symposium on Programming, S.D. Swierstra (Ed.), Amsterdam, The Netherlands, Lecture Notes in Computer Science, no. 1576, Springer-Verlag, 1999, pp. 224–242.

  14. Filinski, A. Representing monads. In Proceedings of the Twenty-First Annual ACM Symposium on Principles of Programming Languages, H.-J. Boehm (Ed.), Portland, Oregon, 1994, pp. 446–457.

  15. Filinski, A. Representing layered monads. In Proceedings of the Twenty-Sixth Annual ACM Symposium on Principles of Programming Languages, 1999, A. Aiken (Ed.), San Antonio, Texas, pp. 175–188.

  16. Filinski, A. A semantic account of type-directed partial evaluation. In International Conference on Principles and Practice of Declarative Programming, G. Nadathur (Ed.), Paris, France, Lecture Notes in Computer Science, no. 1702, Springer-Verlag, 1999, pp. 378–395.

  17. Futamura, Y. Partial evaluation of computation process-An approach to a compiler-compiler. Higher-Order and Symbolic Computation, 12(4) (1999) 363–397. Reprinted from Systems, Computers, Controls, 2(5) (1971).

    Google Scholar 

  18. Grobauer, B. and Yang, Z. Source code for the second Futamura projection for type-directed partial evaluation in ML, 2000 Available at http://www.brics.dk/~tdpe/second FP/sources.tgz.

  19. Hatcliff, J. and Danvy, O. A computational formalization for partial evaluation. Mathematical Structures in Computer Science, 7 (1997) 507–541. Extended version available as BRICS Technincal Report RS–96–34.

    Google Scholar 

  20. Holst, C.K. and Launchbury, J. Handwriting cogen to avoid problems with static typing. In Draft Proceedings, 4th Annual Glasgow Workshop on Functional Programming, Skye, Scotland, 1991, pp. 210–218.

  21. Jones, N.D. Challenging problems in partial evaluation and mixed computation. In Partial Evaluation and Mixed Computation, D. Bjø rner, A.P. Ershov, and N.D. Jones (Eds.), 1988, pp. 1–14.

  22. Jones, N.D., Gomard, C.K., and Sestoft, P. Partial Evaluation and Automatic Program Generation, Prentice Hall International Series in Computer Science. Prentice-Hall Internation, 1993.

  23. Jones N.D. Sestoft, P. and Sø ndergaard, H. MIX: A self-applicable partial evaluator for experiments in compiler generation. Lisp and Symbolic Computation, 2(1) (1989) 9–50.

    Google Scholar 

  24. Lawall, J.L. and Danvy,O. Continuation-based partial evaluation. In Proceedings of the 1994 ACM Conference on Lisp and Functional Programming, C.L. Talcott (Ed.), Orlando, Florida, 1994, pp. 227–238.

  25. Milner, R., Tofte, M. Harper, R., and MacQueen, D. The Definition of Standard ML (Revised). MIT Press, 1997.

  26. Moggi, E. Computational lambda-calculus and monads. In Proceedings of the Fourth Annual IEEE Symposium on Logic in Computer Science, R. Parikh (Ed.), Pacific Grove, California, 1989, pp. 14–23.

  27. Paulson, L.C. Compiler generation from denotational semantics. In Methods and Tools for Compiler Construction, B. Lorho (Ed.), 1984, pp. 219–250.

  28. Rhiger,M. Deriving a statically typed type-directed partial evaluator. In ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation (PEPM'99), Proceedings. Department of Computer Science, University of Aarhus, O. Danvy (Ed.), 1999, pp. 25–29. BRICS Technical Report BRICS-NS–99–1.

  29. Rhiger, M. Run-time code generation for type-directed partial evaluation. Progress Report, BRICS PhD School, University of Aarhus, 1999 Available at http://www.brics.dk/~mrhiger.

  30. Sumii, E. Email exchange, February 2000.

  31. Thiemann, P. Combinators for program generation. Journal of Functional Programming 9(5) (1999) 483–525.

    Google Scholar 

  32. Yang, Z. Encoding types in ML-like languages. In Proceedings of the 1998 ACM SIGPLAN International Conference on Functional Programming. P. Hudak and C. Queinnec (Eds.), Baltimore, Maryland, 1998, pp. 289–300. Extended version available as BRICS Technical Report RS–98–9.

Download references

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

About this article

Cite this article

Grobauer, B., Yang, Z. The Second Futamura Projection for Type-Directed Partial Evaluation. Higher-Order and Symbolic Computation 14, 173–219 (2001). https://doi.org/10.1023/A:1012992731199

Download citation

  • Issue Date:

  • DOI: https://doi.org/10.1023/A:1012992731199

Navigation