Macros as Multi-Stage Computations: Type-Safe, Generative, Binding Macros in MacroML
2001 (English)In: Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming (ICFP'01): Florence, Italy, Sept. 3-5, 2001, New York, N.Y.: ACM Press, 2001, p. 74-85Conference paper, Published paper (Refereed)
Abstract [en]
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.
Place, publisher, year, edition, pages
New York, N.Y.: ACM Press, 2001. p. 74-85
National Category
Computer Systems
Identifiers
URN: urn:nbn:se:hh:diva-20987DOI: 10.1145/507669.507646ISI: 000172134900009Scopus ID: 2-s2.0-0034782593Libris ID: 12438527ISBN: 1-58113-415-0 OAI: oai:DiVA.org:hh-20987DiVA, id: diva2:588289
Conference
6th ACM SIGPLAN Internatinal Conference on Functional Programming (ICFP'01), Florence, Italy, 3-5 September, 2001
Note
This work was supported in part by the National Science Foundation under Grant # CCR-9987458.
This material is based upon work supported by the National Science Foundation under Grant # CCR-0196063.
W. Taha funded by subcontract #8911-48186 from Johns Hopkins University under NSF agreement Grant # EIA-9996430.
2013-01-152013-01-142021-05-11Bibliographically approved