Hostname: page-component-5d59c44645-7l5rh Total loading time: 0 Render date: 2024-02-25T16:10:29.470Z Has data issue: false hasContentIssue false

A partial evaluator for the untyped lambda-calculus

Published online by Cambridge University Press:  07 November 2008

Carsten K. Gomard
Affiliation:
gomard@diku.dk, neil@diku.dkDIKU, Department of Computer Science, University of Copenhagen
Neil D. Jones
Affiliation:
gomard@diku.dk, neil@diku.dkDIKU, Department of Computer Science, University of Copenhagen
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

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.

Type
Article
Copyright
Copyright © Cambridge University Press 1991

References

Appel, A. 1985. Semantics-directed code generation. In 12th ACM Symposium on Principle of Programming Languages, pp. 315–24.Google Scholar
Beckman, L. et al. 1976. A partial evaluator, and its use as a programming tool. Artificial Intelligence 7 (4): 319–57.Google Scholar
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.Google Scholar
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.Google Scholar
Bondorf, A. and Danvy, O. 1989. Automatic autoprojection for recursive equations with global variables and abstract data types, 1989. (Submitted for publication).Google Scholar
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).Google Scholar
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.Google Scholar
Consel, C. and Danvy, O. 1989. Partial evaluation of pattern matching in strings, Information Processing Letters 30 (2): 7986.Google Scholar
Damas, L. and Milner, R. 1982. Principal type-schemes for functional programs. In 9th ACM Symposium on Principles of Programming Languages, pp. 207–12.Google Scholar
Ershov, A. P. 1978 On the essence of compilation. In Neuhold, E. J. (editor) Formal Description of Programming Concepts, pp. 391420. North-Holland.Google Scholar
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.Google Scholar
Fuller, D. A. and Abramsky, S. 1988. Mixed computation of Prolog programs. New Generation Computing 6 (2, 3): 119–41.Google Scholar
Futurama, Y. 1971.Partial evaluation of computation process – an approach to a compiler–compiler. Systems, Computers, Controls 2 (5): 4550.Google Scholar
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.Google Scholar
Gomard, C. K. 1989. Higher Order Partial Evaluation – HOPE for the Lambda Calculus, Master's thesis, DIKU, University of Copenhagen, Denmark (September).Google Scholar
Gomard, C. K. and Jones, N. D. 1989. Compiler generation by partial evaluation: a case study. In Gallaire, H. (editor), Information Processing 89. IFIP.Google Scholar
Gomard, C. K. 1990. Partial Type Inference for Untyped Functional Programs. In 1990 ACM Conference on Lisp and Functional Programming, pp. 282287.Google Scholar
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).Google Scholar
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.Google Scholar
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.Google Scholar
Huet, G. 1976. Resolution d'equations dans les langages d'ordre 1, 2, …, ω. PhD thesis , Univ. de Paris VII.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
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).Google Scholar
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.Google Scholar
Lombardi, L. A. 1967. Incremental computation. In Alt, F. L. and Rubinoff, M. (editors), Advances in Computers 8, pp. 247333. Academic Press.Google Scholar
Milner, R. 1978. A theory of type polymorphism in programming, Journal of Computer and System Sciences 17 (3): 348–75.Google Scholar
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.Google Scholar
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.Google Scholar
Morris, F.L. 1973. Advice on structuring compilers and proving them correct. In 1st ACM Symposium on Principles of Programming Languages, pp. 144–52.Google Scholar
Mosses, P. 1979. SIS – Semantics Implementation System, Reference Manual and User Guide, DAIMI Report MD-30, DAIMI, University of Århus, Denmark.Google Scholar
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.Google Scholar
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.Google Scholar
Paulson, L. 1982. A semantics-directed compiler generator. In 9th ACM Symposium on Principles of Programming Languages, pp. 224–33.Google Scholar
Pleban, U. 1984. Compiler prototyping using formal semantics, SIGPLAN Notices 19 (6): 94105.Google Scholar
Plotkin, G. 1975. Call-by-name, call-by-value and the lambda calculus, Theoretical Computer Science 1, 125–59.Google Scholar
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-HollandGoogle Scholar
Schmidt, D. A. 1985. Detecting global variables in denotational specifications, ACM Transactions on Programming Languages and Systems 7 (2): 229310.Google Scholar
Schmidt, D. A. 1986. Denotational Semantics. Allyn and Bacon.Google Scholar
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.Google Scholar
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).Google Scholar
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.Google Scholar
Sestoft, P. 1989. Replacing function parameters by global variables. In Functional Programming Languages and Computer Architecture, London, September 89. ACM Press and Addison-Wesley.Google Scholar
Stoy, J. 1977. Denotational Semantics: The Scott-Strachey Approach to Programming Language Theory. MIT Press.Google Scholar
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.Google Scholar
Wadler, P. 1990. Linear types can change the world! ISIP TC Working Conference on Programming Concepts and Methods, Sea of Galilee,Israel,April 1990.Google Scholar
Wand, M. 1982. Semantics-directed machine architecture. In 9th ACM Symposium on Principles of Programming Languages, pp. 234–41.Google Scholar
Wand, M. 1984. A semantic prototyping system. In SIGPLAN '84 Symposium on Compiler Construction, PP. 213–21.Google Scholar
Wand, M. 1986. Finding the source of type errors. In 13th ACM Symposium on Principles of Programming Languages, pp. 3843.Google Scholar
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).Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.