ACM Home Page
Please provide us with feedback. Feedback
Building interpreters by composing monads
Full text PdfPdf (1.68 MB)
Source Annual Symposium on Principles of Programming Languages archive
Proceedings of the 21st ACM SIGPLAN-SIGACT symposium on Principles of programming languages table of contents
Portland, Oregon, United States
Pages: 472 - 492  
Year of Publication: 1994
ISBN:0-89791-636-0
Author
Guy L. Steele, Jr.  Thinking Machines Corporation, 245 First Street, Cambridge, Massachusetts
Sponsors
SIGACT: ACM Special Interest Group on Algorithms and Computation Theory
SIGPLAN: ACM Special Interest Group on Programming Languages
Publisher
ACM  New York, NY, USA
Bibliometrics
Downloads (6 Weeks): 7,   Downloads (12 Months): 50,   Citation Count: 21
Additional Information:

abstract   references   cited by   index terms   collaborative colleagues  

Tools and Actions: Request Permissions Request Permissions    Review this Article  
DOI Bookmark: Use this link to bookmark this Article: http://doi.acm.org/10.1145/174675.178068
What is a DOI?

ABSTRACT

We exhibit a set of functions coded in Haskell that can be used as building blocks to construct a variety of interpreters for Lisp-like languages. The building blocks are joined merely through functional composition. Each building block contributes code to support a specific feature, such as numbers, continuations, functions calls, or nondeterminism. The result of composing some number of building blocks is a parser, an interpreter, and a printer that support exactly the expression forms and data types needed for the combined set of features, and no more. The data structures are organized as pseudomonads, a generalization of monads that allows composition. Functional composition of the building blocks implies type composition of the relevant pseudomonads. Our intent was that the Haskell type resolution system ought to be able to deduce the appropriate data types automatically. Unfortunately there is a deficiency in current Haskell implementations related to recursive data types: circularity must be reflected statically in the type definitions. We circumvent this restriction by applying a purpose-built program simplifier that performs partial evaluation and a certain amount of program algebra. We construct a wide variety of interpreters in the style of Wadler by starting with the building blocks and a page of boiler-plate code, writing three lines of code (one to specify the building blocks and two to (redundantly) specify type compositions), and then applying the simplifier. The resulting code is acceptable Haskell code. We have tested a dozen different interpreters with various combinations of features. In this paper we discuss the overall code structuring strategy, exhibit several building blocks, briefly describe the partial evaluator, and present a number of automatically generated interpreters.


REFERENCES

Note: OCR errors may be found in this Reference List extracted from the full text article. ACM has opted to expose the complete List rather than only correct and linked references.

 
1
Apple Computer, Inc. Inside Maczntosh (five volumes). Addison-Wesley (Reading, Massachusetts, 1985-86).
 
2
Hudak, Paul, Peyton Jones, Simon, and Wadler, Philip, editors. Report on the Programming Language Haskell: A Non-Strict, Purely Functional Language (Version 1.1). Technical Report. Yale University and Glasgow University (New Haven Glasgow (r sp~~tiwly), August 1991).
 
3
Jones, Mark P. Personal communication to Guy Steele, September 1993.
4
 
5
 
6
Moggi, Eugenio. An Abstract Vzew of Programmint Languages. Technical Report ECS-LFCS-90- 113. Laboratory for Foundations of Computer Science, University of Edinburgh (Edinburgh, Scotland, April 1990). Lecture notes for a course taught at Stanford University, Spring 1989.
7
 
8
 
9
Rees, Jonathan. Personal communication to Guy Steele, October 1993.
10
 
11
Steele, Guy L., Jr. How to Compose Monads. Technical Report. Thinking Machines Corporation (Cambridge, Massachusetts, July 1993). Unpublished.
 
12
 
13
 
14
15
16
17
 
18
 
19
Wegbreit, Ben, Holloway, Glenn, Spitzen, Jay, and Townley, Judy. ECL Programmer's Manual. Technical Report 23-74. Harvard University Center for Research in Computing Technology (Cambridge, Massachusetts, December 1974).

CITED BY  21