Skip to main content Accessibility help
×
×
Home

A partial evaluator for the untyped lambda-calculus

  • Carsten K. Gomard (a1) and Neil D. Jones (a1)
Abstract

This article describes theoretical and practical aspects of an implemented self-applicable partial evaluator for the untyped lambda-calculus with constants and a fixed point operator. To the best of our knowledge, it is the first partial evaluator that is simultaneously higher-order, non-trivial, and self-applicable.

Partial evaluation produces a residual program from a source program and some of its input data. When given the remaining input data the residual program yields the same result that the source program would when given all its input data. Our partial evaluator produces a residual lambda-expression given a source lambda-expression and the values of some of its free variables. By self-application, the partial evaluator can be used to compile and to generate stand-alone compilers from a denotational or interpretive specification of a programming language.

An essential component in our self-applicable partial evaluator is the use of explicitbinding time information. We use this to annotate the source program, marking asresidual the parts for which residual code is to be generated and marking aseliminable the parts that can be evaluated using only the data that is known during partial evaluation. We give a simple criterion,well-annotatedness, that can be used to check that the partial evaluator can handle the annotated higher-order programs without committing errors.

Our partial evaluator is simple, is implemented in a side-effect free subset of Scheme, and has been used to compile and to generate compilers and a compiler generator. In this article we examine two machine-generated compilers and find that their structures are surprisingly natural.

Copyright
References
Hide All
Appel, A. 1985. Semantics-directed code generation. In 12th ACM Symposium on Principle of Programming Languages, pp. 315–24.
Beckman, L. et al. 1976. A partial evaluator, and its use as a programming tool. Artificial Intelligence 7 (4): 319–57.
Bondorf, A. 1989. A self-applicable partial evaluator for term rewriting systems. In Diaz, J. and Orejas, F. (editors), TAPSOFT '90. Proc. Int. Conf. Theory and Practice of Software Development, Barcelona, Spain, March 1989. Lecture Notes in Computer Science, 352, pp. 8195. Springer-Verlag.
Bondorf, A. 1990. Automatic autoprojection of higher order recursive equations. In Jones, N. (editor), ESOP '90, Third European Symposium on Programming, Copenhagen, Denmark. Lecture Notes in Computer Science, 432. Springer-Verlag.
Bondorf, A. and Danvy, O. 1989. Automatic autoprojection for recursive equations with global variables and abstract data types, 1989. (Submitted for publication).
Bondorf, A., Jones, N. D., Mogensen, T. and Sestoft, P. 1988. Binding Time Analysis and the Taming of Self-Application. Draft, 18 pages, DIKU , University of Copenhagen, Denmark (August).
Consel, C. 1988. New insights into partial evaluation: the Schism Experiment. In Gonzinger, H. (editor), ESOP '88, 2nd European Symposium on Programming, Nancy, France, March 1988. Lecture Notes in Computer Science, 300, pp. 236–46. Springer-Verlag.
Consel, C. and Danvy, O. 1989. Partial evaluation of pattern matching in strings, Information Processing Letters 30 (2): 7986.
Damas, L. and Milner, R. 1982. Principal type-schemes for functional programs. In 9th ACM Symposium on Principles of Programming Languages, pp. 207–12.
Ershov, A. P. 1978 On the essence of compilation. In Neuhold, E. J. (editor) Formal Description of Programming Concepts, pp. 391420. North-Holland.
Ershov, A. P. and Itkin, V. E. (1977). Correctness of mixed computation in Algol-like programs. In Gruska, J. (editor), Mathematical Foundations of Computer Science, Tatranská Lomnica, Czechoslovakia. Lecture Notes in Computer Science, 53, pp. 5977. Springer-Verlag.
Fuller, D. A. and Abramsky, S. 1988. Mixed computation of Prolog programs. New Generation Computing 6 (2, 3): 119–41.
Futurama, Y. 1971.Partial evaluation of computation process – an approach to a compiler–compiler. Systems, Computers, Controls 2 (5): 4550.
Goguen, G., Thatcher, J. W., Wagner, E. G. and Wright, J. B. 1977. Initial algebra semantics and continuous algebras, Journal of the ACM 24: 6895.
Gomard, C. K. 1989. Higher Order Partial Evaluation – HOPE for the Lambda Calculus, Master's thesis, DIKU, University of Copenhagen, Denmark (September).
Gomard, C. K. and Jones, N. D. 1989. Compiler generation by partial evaluation: a case study. In Gallaire, H. (editor), Information Processing 89. IFIP.
Gomard, C. K. 1990. Partial Type Inference for Untyped Functional Programs. In 1990 ACM Conference on Lisp and Functional Programming, pp. 282287.
Guzowski, M. A. 1988. Towards Developing a Reflexive Partial Evaluator for an Interesting Subset of LISP, Master's thesis, Department of Computer Engineering and Science, Case Western Reserve University, Cleveland, Ohio (January).
Hansen, T. A. and Träff, J. L. 1989. Memorization and its use in lazy and incremental program generation, Master's thesis, DIKU, University of Copenhagen.
Holst, N. C. K. 1988. Language triplets; the AMIX approach. In Bjørner, D., Ershov, A. P. and Jones, N. D. (editors), Partial Evaluation and Mixed Computation, pp. 167–85, North-Holland.
Huet, G. 1976. Resolution d'equations dans les langages d'ordre 1, 2, …, ω. PhD thesis , Univ. de Paris VII.
Jones, N. D. 1988. Automatic program specialization: a re-examination from basic principles. In Bjørner, D., Ershov, A. P. and Jones, N. D. (editors), Partial Evaluation and Mixed Computation, pp. 225–82, North-Holland.
Jones, Neil D. and Muchnick, Steven S. 1978. TEMPO: A Unified Treatment of Binding Time and Parameter Passing Concepts in Programming Languages. Lecture Notes in Computer Science 66. Springer-Verlag.
Jones, N. D., Sestoft, P. and Søndergaard, H. 1985. An experiment in partial evaluation: the generation of a compiler generator. In Jouannaud, J.-P. (editor), Rewriting Techniques and Applications, Dijon, France. Lecture Notes in Computer Science, 202, pp. 124–40. Springer-Verlag.
Jones, N. D., Sestoft, P. and Søndergaard, H. 1989. Mix: a self-applicable partial evaluator for experiments in compiler generation. Lisp and Symbolic Computation 2 (1): 950.
Jones, N. D., Gomard, C. K., Bondorf, A., Danvy, O. and Mogensen, T. 1990. A self-applicable partial evaluator for the lambda calculus. In IEEE Computer Society 1990 International Conference on Computer Languages(March).
Kuo, T.-M. and Mishra, P. 1989. Strictness analysis: a new perspective based on type inference. In Functional Programming Languages and Computer Architecture, London, September 89. ACM Press and Addison-Wesley.
Lombardi, L. A. 1967. Incremental computation. In Alt, F. L. and Rubinoff, M. (editors), Advances in Computers 8, pp. 247333. Academic Press.
Milner, R. 1978. A theory of type polymorphism in programming, Journal of Computer and System Sciences 17 (3): 348–75.
Mogensen, T. 1988. Partially static structures in a self-applicable partial evaluator. In Bjørner, D., Ershov, A. P. and Jones, N. D. (editors), Partial Evaluation and Mixed Computation, pp. 325–47, North-Holland.
Mogensen, T. 1989. Binding time analysis for polymorphically typed higher order languages. In Diaz, J. and Orejas, F. (editors), TAPSOFT '89. Proc. Int. Conf. Theory and Practice of Software Development, Barcelona, Spain, March 1989, Lecture Notes in Computer Science 352, pp. 298312. Springer-Verlag.
Morris, F.L. 1973. Advice on structuring compilers and proving them correct. In 1st ACM Symposium on Principles of Programming Languages, pp. 144–52.
Mosses, P. 1979. SIS – Semantics Implementation System, Reference Manual and User Guide, DAIMI Report MD-30, DAIMI, University of Århus, Denmark.
Nielson, F. and Nielson, H. R. 1988a. The TML-Approach to Compiler–Compilers, Technical Report 1988–47, Department of Computer Science, Technical University of Denmark.
Nielson, H.R. and Nielson, F. 1988b. Automatic binding time analysis for a typed λ-calculus. In 15th ACM Symposium on Principles of Programming Languages, pp. 98106.
Paulson, L. 1982. A semantics-directed compiler generator. In 9th ACM Symposium on Principles of Programming Languages, pp. 224–33.
Pleban, U. 1984. Compiler prototyping using formal semantics, SIGPLAN Notices 19 (6): 94105.
Plotkin, G. 1975. Call-by-name, call-by-value and the lambda calculus, Theoretical Computer Science 1, 125–59.
Romanenko, S.A. 1988. A compiler generator produced by a self-applicable specializer can have a surprisingly natural and understandable structure. In Bjørner, D., Ershov, A. P. and Jones, N. D. (editors) Partial Evaluation and Mixed Computation, pp. 445–63. North-Holland
Schmidt, D. A. 1985. Detecting global variables in denotational specifications, ACM Transactions on Programming Languages and Systems 7 (2): 229310.
Schmidt, D. A. 1986. Denotational Semantics. Allyn and Bacon.
Schmidt, D. A. 1988. Static properties of partial evaluation. In Bjørner, D., Ershov, A. P. and Jones, N. D. (editors), Partial Evaluation and Mixed Computation, pp. 465–83. North-Holland.
Schooler, R. 1984. Partial Evaluation as a Means of Language Extensibility, Master's thesis, 84 pages, MIT/LCS/TR-324, Laboratory for Computer Science, MIT, Cambridge, Massachusetts (August).
Sestoft, P. 1988. Automatic call unfolding in a partial evaluator. In Bjørner, D., Ershov, A. P. and Jones, N. D. (editors), Partial Evaluation and Mixed Computation, pp. 485506. North-Holland.
Sestoft, P. 1989. Replacing function parameters by global variables. In Functional Programming Languages and Computer Architecture, London, September 89. ACM Press and Addison-Wesley.
Stoy, J. 1977. Denotational Semantics: The Scott-Strachey Approach to Programming Language Theory. MIT Press.
Turchin, V.F. 1980. The use of metasystem transition in theorem proving and program optimization. In De Bakker, J. and van Leeuven, J. (editors), Automata, Languages and Programming. Seventh ICALP, Noordwijkerhout, The Netherlands. Lecture Notes in Computer Science 85, pp. 645–57. Springer-Verlag.
Wadler, P. 1990. Linear types can change the world! ISIP TC Working Conference on Programming Concepts and Methods, Sea of Galilee,Israel,April 1990.
Wand, M. 1982. Semantics-directed machine architecture. In 9th ACM Symposium on Principles of Programming Languages, pp. 234–41.
Wand, M. 1984. A semantic prototyping system. In SIGPLAN '84 Symposium on Compiler Construction, PP. 213–21.
Wand, M. 1986. Finding the source of type errors. In 13th ACM Symposium on Principles of Programming Languages, pp. 3843.
Weis, P. 1987. Le Système SAM: Metacompilation très efficace à l'aide d' operateur sémantiques, PhD thesis, l'Université Paris VII (in French).
Recommend this journal

Email your librarian or administrator to recommend adding this journal to your organisation's collection.

Journal of Functional Programming
  • ISSN: 0956-7968
  • EISSN: 1469-7653
  • URL: /core/journals/journal-of-functional-programming
Please enter your name
Please enter a valid email address
Who would you like to send this to? *
×

Metrics

Full text views

Total number of HTML views: 0
Total number of PDF views: 0 *
Loading metrics...

Abstract views

Total abstract views: 0 *
Loading metrics...

* Views captured on Cambridge Core between <date>. This data will be updated every 24 hours.

Usage data cannot currently be displayed

A partial evaluator for the untyped lambda-calculus

  • Carsten K. Gomard (a1) and Neil D. Jones (a1)
Submit a response

Discussions

No Discussions have been published for this article.

×

Reply to: Submit a response


Your details


Conflicting interests

Do you have any conflicting interests? *