|
ABSTRACT
With few exceptions, macros have traditionally been viewed as operations on syntax trees or even on plain strings. This view makes macros seem ad hoc, and is at odds with two desirable features of contemporary typed functional languages: static typing and static scoping. At a deeper level, there is a need for a simple, usable semantics for macros. This paper argues that these problems can be addressed by formally viewing macros as multi-stage computations. This view eliminates the need for freshness conditions and tests on variable names, and provides a compositional interpretation that can serve as a basis for designing a sound type system for languages supporting macros, or even for compilation. To illustrate our approach, we develop and present MacroML, an extension of ML that supports inlining, recursive macros, and the definition of new binding constructs. The latter is subtle, and is the most novel addition in a statically typed setting. The semantics of a core subset of MacroML is given by an interpretation into MetaML, a statically-typed multi-stage programming language. It is then easy to show that MacroML is stage- and type-safe: macro expansion does not depend on runtime evaluation, and both stages do not "go wrong.
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
|
|
| |
2
|
BARENDREGT, H. P. The Lambda Calculus: Its Syntax and Semantics, revised ed, vol. 103 of Studies in Logic and the Foundations of Mathematics. North-Holland, Amsterdam, 1984.
|
| |
3
|
BENAISSA, Z. E.-A., MOGGI, E., TAHA, W., AND SHEARD, T. Logical modalities and multi-stage programming. In Federated Logic Conference (FLoe,) Satellite Workshop on Intuitionistic Modal Logics and Applications (IMLA) (1999).
|
| |
4
|
|
| |
5
|
|
| |
6
|
CURRY, H. B., AND FEYS, R. Combinatory Logic, Volume I. Studies in Logic and the Foundations of Mathematics. North-Holland, Amsterdam, 1958. Second printing 1968.
|
| |
7
|
|
 |
8
|
|
| |
9
|
|
 |
10
|
|
| |
11
|
|
| |
12
|
|
| |
13
|
|
| |
14
|
|
| |
15
|
|
| |
16
|
G0MARD, C. K., AND JONES, N. D. A partial evaluator for untyped lambda calculus. Journal of Functional Programming 1, 1 (1991), 21-69.
|
| |
17
|
GRIFFIN, T. G. Notational definitions--a formal account. In Proceedings of the Third Symposium on Logic in Computer Science (1988).
|
| |
18
|
|
| |
19
|
|
| |
20
|
|
 |
21
|
Eugene Kohlbecker , Daniel P. Friedman , Matthias Felleisen , Bruce Duba, Hygienic macro expansion, Proceedings of the 1986 ACM conference on LISP and functional programming, p.151-161, August 1986, Cambridge, Massachusetts, United States
[doi> 10.1145/319838.319859]
|
 |
22
|
Jeffrey R. Lewis , John Launchbury , Erik Meijer , Mark B. Shields, Implicit parameters: dynamic scoping with static types, Proceedings of the 27th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, p.108-118, January 19-21, 2000, Boston, MA, USA
[doi> 10.1145/325694.325708]
|
| |
23
|
|
| |
24
|
MIILLER, D. An extension to NIL to handle bound variables in data structures: Preliminary report. In Informal Proceedings of the Logical Frameworks BRA Workshop (June 1990). Available as UPenn CIS technical report MS-CIS-90-59.
|
| |
25
|
|
| |
26
|
|
| |
27
|
MOGGI, E. A categorical account of two-level languages. In Mathematics Foundations of Program Semantics (1997). Elsevier Science.
|
| |
28
|
|
| |
29
|
|
| |
30
|
MONNIER, S., AND SHA0, Z. Inlirung as staged computation. Tech. Rep. YALEU/DCS/TR-l 193, Department of Computer Science. Yale University, Mar. 2000.
|
 |
31
|
|
| |
32
|
|
| |
33
|
|
| |
34
|
|
| |
35
|
Oregon Graduate Institute Technical Reports. P.C. Box 91000, Portland. OR 972911000,IJSA. Available online front ftp://cse.ogi.edu/pub/tech-repo~s/README.html. Last viewed August 1999.
|
| |
36
|
|
 |
37
|
|
| |
38
|
|
| |
39
|
PLOTKIN, G. D. Call-by-name, call-by-value and the lambda-calculus. Theoretical Computer Science 1 (1975), 125-159.
|
| |
40
|
|
| |
41
|
SANDS, D. Computing with contexts: A simple approach. In Second Workshop on HigherOrder Operational Techniques in Semantics (HOOTS II), A. 0. Gordon. A. NI. Pitts, and C. L. Talcott, Eds., vol. 10 of Electron,( Notes in Theoretical Computer Science. Elsevier Science Publishers B.V., 1998.
|
| |
42
|
SHEARD, T. Using MetahIL: A staged programming language. Lecture Notes in Computer Science 1608 1 207-239.
|
 |
43
|
Mark Shields , Tim Sheard , Simon Peyton Jones, Dynamic typing as staged type inference, Proceedings of the 25th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, p.289-302, January 19-21, 1998, San Diego, California, United States
[doi> 10.1145/268946.268970]
|
| |
44
|
|
 |
45
|
|
| |
46
|
|
| |
47
|
TAHA, W., AND MAKHOLM, H. Tag elimination - or type specialisation is a type-indexed effect. In Subtyping and Dependent Types in Programming. APPSEM Workshop. INRIA technical report, 2000.
|
 |
48
|
|
| |
49
|
THIEMANN, P. AND DUSSART, D. Partial evaluation for higher-order languages with state. Available online from http://www.informatik.uni_freiburgdethiemanri/papers index,html. 1996
|
 |
50
|
|
| |
51
|
|
CITED BY 12
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cristiano Calcagno , Walid Taha , Liwen Huang , Xavier Leroy, Implementing multi-stage languages using ASTs, Gensym, and reflection, Proceedings of the second international conference on Generative programming and component engineering, p.57-76, September 22-25, 2003, Erfurt, Germany
|
|
|
|
|
|
|
|
|
|
|
|
|
|