2017 · 13 citations · 26 references
ComputingComputer ScienceCompilersProgramming LanguagesSyntaxData TypesDomain-specific LanguagesIntermediate RepresentationType CheckingType SystemsAbstraction MechanismsHigh-level Intermediate RepresentationIntermediate Representation DesignMetaprogrammingPattern Matching SemanticsType-level Programming
Quasiquotes have been shown to greatly simplify the task of metaprogramming. This is in part because they hide the data structures of the intermediate representation (IR), instead allowing metaprogrammers to use the concrete syntax of the language they manipulate. Scala has had "syntactic" quasiquotes for a long time, but still misses a statically-typed version like in MetaOCaml, Haskell and F#. This safer flavor of quasiquotes has been particularly useful for staging and domain-specific languages. In this paper we present Squid, a metaprogramming system for Scala that fills this gap. Squid quasiquotes are novel in three ways: they are the first statically-typed quasiquotes we know that allow code inspection (via pattern matching); they are implemented purely as a macro library, without modifications to the compiler; and they are reusable in the sense that they can manipulate different IRs. Adapting (or binding) a new IR to Squid is done simply by implementing a well-defined interface in the style of object algebras (i.e., tagless-final). We detail how Squid is implemented, leveraging the metaprogramming tools already offered by Scala, and show three application examples: the definition of a binding for a DSL in the style of LMS; a safe ANF conversion; and the introduction of type-safe, hygienic macros as an alternative to the current macro system.
26
Frank Pfenning, Conal Elliott · ACM SIGPLAN Notices · 1988 · 587 citations · Full text
Template meta-programming for Haskell
Tim Sheard, Simon Peyton Jones · 2002 · 548 citations
The essence of compiling with continuations
Cormac Flanagan, Amr Sabry, Bruce F. Duba et al. · 1993 · 533 citations
Revised <sup>4</sup> report on the algorithmic language scheme
Hal Abelson, R. Kent Dybvig, Christopher T. Haynes et al. · ACM SIGPLAN Lisp Pointers · 1991 · 370 citations · Full text
Erik Meijer, Brian Beckman, Gavin Bierman · 2006 · 369 citations