Publications:Macros as Multi-Stage Computations : Type-Safe, Generative, Binding Macros in MacroML

Jump to: navigation, search

Do not edit this section

Keep all hand-made modifications below

Title Macros as Multi-Stage Computations : Type-Safe, Generative, Binding Macros in MacroML
Author Steven Ganz and Amr Sabry and Walid Taha
Year 2001
PublicationType Conference Paper
Conference ICFP'01. International Conference on Functional Programming
Diva url
Abstract With few exceptions, macros have traditionally been viewedas operations on syntax trees or even on plain strings. Thisview 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, thereis a need for a simple, usable semantics for macros. Thispaper argues that these problems can be addressed by formally viewing macros as multi-stage computations. Thisview eliminates the need for freshness conditions and testson variable names, and provides a compositional interpretation that can serve as a basis for designing a sound typesystem for languages supporting macros, or even for compilation.To illustrate our approach, we develop and present MacroML, an extension of ML that supports inlining, recursivemacros, and the definition of new binding constructs. Thelatter is subtle, and is the most novel addition in a staticallytyped setting. The semantics of a core subset of MacroML isgiven by an interpretation into MetaML, a statically-typedmulti-stage programming language. It is then easy to showthat MacroML is stage- and type-safe: macro expansiondoes not depend on runtime evaluation, and both stagesdo not “go wrong”.