New Generation Computing

, Volume 20, Issue 1, pp 53–73 | Cite as

A unifying approach to goal-directed evaluation

  • Olivier Danvy
  • Bernd Grobauer
  • Morten Rhiger
Special Feature


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.


(Type-directed) partial evaluation Computational monads Con|tinuations (Run-time) code generation Code templates 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1).
    Appel, A. W.,Compiling with Continuations, Cambridge University Press, New York, 1992.Google Scholar
  2. 2).
    Byrd, L., “Understanding the Control of Prolog Programs,”Technical Report 151, University of Edinburgh, 1980.Google Scholar
  3. 3).
    Carlsson, M., “On Implementing Prolog in Functional Programming,”New Generation Computing, 2, 4, pp. 347–359, 1984.MathSciNetCrossRefGoogle Scholar
  4. 4).
    Church, A.,The Calculi of Lambda-Conversion, Princeton University Press, 1941.Google Scholar
  5. 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. 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. 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. 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. 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. 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. 11).
    Griswold, R. E. and Griswold, M. T.,The Icon Programming Language, Prentice Hall, 1983.Google Scholar
  12. 12).
    Griswold, R. E. and Griswold, M. T.,The Implementation of the Icon Programming Language. Princeton University Press, 1986.Google Scholar
  13. 13).
    Gudeman, D. A., “Denotational Semantics of a Goal-directed Language,”ACM Transactions on Programming Languages and Systems, 1992.Google Scholar
  14. 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. 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
  16. 16).
    Hughes, J., “A Novel Representation of Lists and its Application to the Function “reverse”,”Information Processing Letters, 22, 3, pp. 141–144, 1986.CrossRefGoogle Scholar
  17. 17).
    Jones, N. D., Gomard, C. K. and Sestoft, P.,Partial Evaluation and Automatic Program Generation, Prentice-Hall International, 1993. Available online at Scholar
  18. 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. 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. 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
  21. 21).
    Moggi, E., “Computational Lambda-calculus and Monads,” inProc. of the Fourth Annual IEEE Symposium on Logic in Computer Science, pp. 14–23, Pacific Grove, California, IEEE Computer Society Press, June 1989.CrossRefGoogle Scholar
  22. 22).
    Proebsting, T. A., “Simple Translation of Goal-directed Evaluation,” in Cytron,7), pp. 1–6.Google Scholar
  23. 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
  24. 24).
    Reynolds, J. C., “Definitional Interpreters for Higher-order Programming Languages,”Higher-Order and Symbolic Computation, 11, 4, pp. 363–397, 1998. Reprinted from the Proc. of the 25th ACM National Conference, 1972.CrossRefGoogle Scholar
  25. 25).
    Rhiger, M.,PhD thesis, BRICS PhD School, University of Aarhus, Aarhus, Denmark, 2001. Forthcoming.Google Scholar
  26. 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. 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
  28. 28).
    Wadler, P., “Comprehending Monads,”Mathematical Structures in Computer Science, 2, 4, pp. 461–493, December 1992.MathSciNetCrossRefGoogle Scholar
  29. 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. 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

Copyright information

© Ohmsha, Ltd. and Springer 2002

Authors and Affiliations

  • Olivier Danvy
    • 1
  • Bernd Grobauer
    • 1
  • Morten Rhiger
    • 1
  1. 1.BRICS, Department of Computer ScienceUniversity of AarhusAarhus CDenmark

Personalised recommendations