Communications of the ACM
POPL '82 Proceedings of the 9th ACM SIGPLAN-SIGACT symposium on Principles of programming languages
SKIM - The S, K, I reduction machine
LFP '80 Proceedings of the 1980 ACM conference on LISP and functional programming
The semantic elegance of applicative languages
FPCA '81 Proceedings of the 1981 conference on Functional programming languages and computer architecture
Functional programming with combinators
Journal of Symbolic Computation
Correct flow analysis in continuation semantics
POPL '88 Proceedings of the 15th ACM SIGPLAN-SIGACT symposium on Principles of programming languages
Efficient compilation of lazy evaluation
SIGPLAN '84 Proceedings of the 1984 SIGPLAN symposium on Compiler construction
A combinator-based compiler for a functional language
POPL '84 Proceedings of the 11th ACM SIGACT-SIGPLAN symposium on Principles of programming languages
LFP '84 Proceedings of the 1984 ACM Symposium on LISP and functional programming
Efficient compilation of lazy evaluation
ACM SIGPLAN Notices - Best of PLDI 1979-1999
Hi-index | 0.00 |
It is our purpose here to present an alternative evaluation mechanism for combinator expressions, namely a relatively straightforward compilation algorithm which translates combinators to fixed-program code for a stack machine. The resulting code is faithful to Turner's use of non-strict functions, in that it performs normal order evaluation. We show how this code can be made more efficient by performing call-by-need evaluation (without changing the semantics of the language) and consider some flow-analysis-based optimizations, as well. The remainder of this paper is organized as follows: We first review (briefly) Turner's arguments in favor of using combinators and how to translate function definitions to combinator expressions in Section 2. Next, in Section 3, we present our translation of combinator expressions to call-by-name stack machine code and the evaluation of a simple program in our model. In Section 4 we show how to eliminate repeated evaluation of argument expressions (or, equivalently, optimize evaluation of S combinator expressions) by using call by need. In Section 5 we consider flow-analysis-based optimizations which can significantly improve the code generated by the naive algorithms of Sections 3 and 4. Finally, Section 6 presents conclusions and suggestions for further work in this area.