A unifying approach to goal-directed evaluation
- 34 Downloads
Goal-directed evaluation, as embodied in Icon and Snobol, is built on the notions of backtracking and of generating successive results, and therefore it has always been something of a challenge to specify and implement. In this article, we address this challenge using computational monads and partial evaluation.
We consider a subset of Icon and we specify it with a monadic semantics and a list monad. We then consider a spectrum of monads that also fit the bill, and we relate them to each other. For example, we derive a continuation monad as a Church encoding of the list monad. The resulting semantics coincides with Gudeman’s continuation semantics of Icon.
We then compile Icon programs by specializing their interpreter (i.e., by using the first Futamura projection), using type-directed partial evaluation. Through various back ends, including a run-time code generator, we generate ML code, C code, and OCaml byte code. Binding-time analysis and partial evaluation of the continuation-based interpreter automatically give rise to C programs that coincide with the result of Proebsting’s optimized compiler.
Keywords(Type-directed) partial evaluation Computational monads Con|tinuations (Run-time) code generation Code templates
Unable to display preview. Download preview PDF.
- 1).Appel, A. W.,Compiling with Continuations, Cambridge University Press, New York, 1992.Google Scholar
- 2).Byrd, L., “Understanding the Control of Prolog Programs,”Technical Report 151, University of Edinburgh, 1980.Google Scholar
- 4).Church, A.,The Calculi of Lambda-Conversion, Princeton University Press, 1941.Google Scholar
- 5).Consel, C. and Danvy, O., “Tutorial Notes on Partial Evaluation,” inProc. of the Twentieth Annual ACM Symposium on Principles of Programming Languages (Graham, S. L. ed.), pp. 493–501, Charleston, South Carolina, ACM Press, January 1993.Google Scholar
- 6).Consel, C. and Noël, F., “A General Approach for Run-time Specialization and its Application to C,” inProc. of the Twenty-Third Annual ACM Symposium on Principles of Programming Languages (Steele, G. L. ed.), pp. 145–156, St. Petersburg Beach, Florida, ACM Press, January 1996.Google Scholar
- 7).Proc. of the ACM SIGPLAN’97 Conference on Programming Languages Design and Implementation (Cytron, R. K., ed.), SIGPLAN Notices,32, 5, Las Vegas, Nevada, ACM Press, June 1997.Google Scholar
- 8).Danvy, O., “Type-directed Partial Evaluation,” inPartial Evaluation — Practice and Theory; Proc. of the 1998 DIKU Summer School (Hatcliff, J., Mogensen, T. Æ. and Thiemann, P., eds.),1706 in Lecture Notes in Computer Science, pp. 367–411, Copenhagen, Denmark, Springer-Verlag, July 1998.Google Scholar
- 9).Danvy, O. and Vestergaard, R., “Semantics-based Compiling: A Case Study in Type-directed Partial Evaluation,” inEighth International Symposium on Programming Language Implementation and Logic Programming (Kuchen, H. and Swierstra, D. eds.),1140 in Lecture Notes in Computer Science, pp. 182–197, Aachen, Germany, Springer-Verlag, September 1996. Extended version available as the technical report BRICS-RS-96-13.Google Scholar
- 10).filinski, A., “Representing Layered Monads,” inProc. of the Twenty-Sixth Annual ACM Symposium on Principles of Programming Languages (Aiken, A. ed.), pp. 175–188, San Antonio, Texas, ACM Press, January 1999.Google Scholar
- 11).Griswold, R. E. and Griswold, M. T.,The Icon Programming Language, Prentice Hall, 1983.Google Scholar
- 12).Griswold, R. E. and Griswold, M. T.,The Implementation of the Icon Programming Language. Princeton University Press, 1986.Google Scholar
- 13).Gudeman, D. A., “Denotational Semantics of a Goal-directed Language,”ACM Transactions on Programming Languages and Systems, 1992.Google Scholar
- 14).Hieb, R., Dybvig, R. K. and Bruggeman, C., “Representing Control in the Presence of First-class Continuations,” inProc. of the ACM SIGPLAN’90 Conference on Programming Languages Design and Implementation (Lang, B. ed.), SIGPLAN Notices,25, 6, pp. 66–77, White Plains, New York, ACM Press, June 1990.Google Scholar
- 15).Hinze, R., “Prological Features in a Functional Setting—Axioms and Implementations,” inThird Fuji International Symposium on Functional and Logic Programming (FLOPS’98) (Sato, M. and Toyama, Y. eds.), pp. 98–122, Kyoto, Japan, World Scientific, April 1998.Google Scholar
- 17).Jones, N. D., Gomard, C. K. and Sestoft, P.,Partial Evaluation and Automatic Program Generation, Prentice-Hall International, 1993. Available online at http://www.dina.kvl.dk/~sestoft/pebook/pebook.html.Google Scholar
- 18).King, D. J. and Wadler, P., “Combining Monads,” inGlasgow Workshop on Functional Programming (Launchbury, J. and Sansom, P. M., eds.), Workshops in Computing, Ayr, Scotland, Springer, Berlin, 1992.Google Scholar
- 19).Leone, M. and Lee, P., “Optimizing ML with Run-time Code Generation,” InProc. of the ACM SIGPLAN’96 Conference on Programming Languages Design and Implementation, SIGPLAN Notices,31, 5, pp. 137–148. ACM Press, May 1996.Google Scholar
- 20).Malmkjaer, K.,Abstract Interpretation of Partial-Evaluation Algorithms, PhD thesis, Department of Computing and Information Sciences, Kansas State University, Manhattan, Kansas, March 1993.Google Scholar
- 22).Proebsting, T. A., “Simple Translation of Goal-directed Evaluation,” in Cytron,7), pp. 1–6.Google Scholar
- 23).Proebsting, T. A. and Townsend, G. M., “A New Implementation of the Icon Language,”Technical Report 99-13, University of Arizona, Department of Computer Science, 1999.Google Scholar
- 25).Rhiger, M.,PhD thesis, BRICS PhD School, University of Aarhus, Aarhus, Denmark, 2001. Forthcoming.Google Scholar
- 26).Sperber, M. and Thiemann, P.,Two for the Price of One: Composing Partial Evaluation and Compilation, in Cytron,7) pp. 215–225.Google Scholar
- 27).Steele Jr., G. L., “Compiler Optimization based on Viewing LAMBDA as RENAME + GOTO,” inArtificial Intelligence: An MIT Perspective (Winston, P. H. and Brown, R. H., eds.),2, The MIT Press, 1979.Google Scholar
- 29).Wadler, P., “Monads for Functional Programming,” inAdvanced Functional Programming (Jeuring, J., and Meijer, E., eds.),925 in Lecture Notes in Computer Science, pp. 24–52. Springer-Verlag, 1995.Google Scholar
- 30).Wallace, R. S., “An Easy Implementation of Pil (PROLOG in LISP),”Association for Computing Machinery Special Interest Group on Artificial Intelligence. SIGART NEWSL., 85, pp. 29–32, July 1983.Google Scholar