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.
Similar content being viewed by others
References
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.
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.
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.
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.
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.
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.
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.
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.
Danvy, O. and Filinski, A. Representing control, a study of the CPS transformation. Mathematical Structures in Computer Science, 2(4), (1992) 361–391.
Danvy, O., Malmkjaer, K., and Palsberg J. Eta-expansion does The Trick. ACM Transactions on Programming Languages and Systems, 8(6) (1996) 730–751.
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
Milner, R., Tofte, M. Harper, R., and MacQueen, D. The Definition of Standard ML (Revised). MIT Press, 1997.
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.
Paulson, L.C. Compiler generation from denotational semantics. In Methods and Tools for Compiler Construction, B. Lorho (Ed.), 1984, pp. 219–250.
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.
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.
Sumii, E. Email exchange, February 2000.
Thiemann, P. Combinators for program generation. Journal of Functional Programming 9(5) (1999) 483–525.
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.
Author information
Authors and Affiliations
Rights 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
Issue Date:
DOI: https://doi.org/10.1023/A:1012992731199