Nothing Special   »   [go: up one dir, main page]

skip to main content
10.1145/2489837.2489840acmotherconferencesArticle/Chapter ViewAbstractPublication PagesecoopConference Proceedingsconference-collections
research-article

Scala macros: let our powers combine!: on how rich syntax and static types work with metaprogramming

Published: 02 July 2013 Publication History

Abstract

Compile-time metaprogramming has been proven immensely useful enabling programming techniques such as language virtualization, embedding of external domain-specific languages, self-optimization, and boilerplate generation among many others.
In the recent production release of Scala 2.10 we have introduced macros, an experimental facility which gives its users compile-time metaprogramming powers. Alongside of the mainline release of Scala Macros, we have also introduced other macro flavors, which provide their users with different interfaces and capabilities for interacting with the Scala compiler.
In this paper, we show how the rich syntax and static types of Scala synergize with macros, through a number of real case studies using our macros (some of which are production systems) such as language virtualization, type providers, materialization of type class instances, type-level programming, and embedding of external DSLs. We explore how macros enable new and unique ways to use pre-existing language features such as implicits, dynamics, annotations, string interpolation and others, showing along the way how these synergies open up new ways of dealing with software development challenges.

References

[1]
M. D. Adams and T. DuBuisson. Template your boilerplate: using template haskell for efficient generic programming. In Haskell 2012, Copenhagen, Denmark, 13 September 2012, pages 13--24, 2012.
[2]
S. Behnke. Scala macros use case: Teaching scala. https://www.learnscala.de/2013/01/28/en/scala-macros-use-case-teaching-scala, 2013.
[3]
E. Brady. Implementation of a general purpose programming language with dependent types. Technical report, 2013.
[4]
R. Brewer. Optimal syntax for python decorators. http://www.aminus.org/rbre/python/pydec.html, Aug. 2004.
[5]
E. Burmako. Macro paradise. http://docs.scala-lang.org/overviews/macros/paradise.html, 2012.
[6]
E. Burmako and M. Odersky. Scala macros, a technical report. In Third International Valentin Turchin Workshop on Metacomputation, 2012.
[7]
P. Butcher. Scalamock, native scala mocking framework. https://github.com/paulbutcher/ScalaMock, 2012.
[8]
J. Cheney, S. Lindley, and P. Wadler. The essence of language-integrated query. Technical report, Mar. 2013.
[9]
B. C. d. S. Oliveira, A. Moors, and M. Odersky. Type classes as objects and implicits. In OOPSLA, pages 341--360, 2010.
[10]
S. Erdweg and F. Lorenzen. Modular and automated type-soundness verification for language extensions, 2013. To appear.
[11]
S. Erdweg, T. Rendel, C. Kästner, and K. Ostermann. SugarJ: library-based syntactic language extensibility. ACM SIGPLAN Notices, 46(10):391--406, Oct. 2011. OOPSLA '11 proceedings.
[12]
M. Felleisen. Adding types to untyped languages. In A. Kennedy and N. Benton, editors, TLDI 2010, Madrid, Spain, January 23, 2010, pages 1--2. ACM, 2010.
[13]
M. Flatt, R. Culpepper, D. Darais, and R. B. Findler. Macros that work together - compile-time bindings, partial expansion, and definition contexts. J. Funct. Program, 22(2):181--216, 2012.
[14]
M. Flatt, R. B. Findler, and M. Felleisen. Scheme with classes, mixins, and traits. In APLAS 2006, Sydney, Australia, November 8--10, 2006, volume 4279, pages 270--289, 2006.
[15]
S. L. P. Jones and R. Lämmel. Scrap your boilerplate. In APLAS 2003, Beijing, China, November 27--29, 2003, 2003.
[16]
V. Jovanovic, V. Nikolaev, N. D. Pham, V. Ureche, S. Stucki, C. Koch, and M. Odersky. Yin-yang: Transparent deep embedding of dsls. Technical Report EPFL-REPORT-185832, EPFL, Lausanne, Switzerland, 2013.
[17]
E. M. Kohlbecker. Syntactic Extensions in the Programming Language Lisp. PhD thesis, Indiana University, Bloomington, IN, Aug. 1986.
[18]
E. Kotelnikov. Scala-idioms, idiom brackets for scala. https://github.com/aztek/scala-idioms, 2013.
[19]
R. Kuhn. Akka, typed channels (experimental), version 2.2-snapshot. http://doc.akka.io/docs/akka/snapshot/scala/typed-channels.html, 2013.
[20]
J. P. Magalhães, A. Dijkstra, J. Jeuring, and A. Löh. A generic deriving mechanism for haskell. In Haskell 2010, Baltimore, MD, USA, 30 September 2010, pages 37--48. ACM, 2010.
[21]
J. P. Magalhães, S. Holdermans, J. Jeuring, and A. Löh. Optimizing generics is easy! In PEPM 2010, Madrid, Spain, January 18--19, 2010, pages 33--42, 2010.
[22]
G. Mainland. Why it's nice to be quoted: quasiquoting for haskell. In Haskell 2007, Freiburg, Germany, September 30, 2007, pages 73--82, 2007.
[23]
C. McBride. The strathclyde haskell enhancement. https://personal.cis.strath.ac.uk/conor.mcbride/pub/she/.
[24]
C. McBride and R. Paterson. Applicative programming with effects. J. Funct. Program, 18(1):1--13, 2008.
[25]
E. Meijer, B. Beckman, and G. Bierman. LINQ: Reconciling object, relations and XML in the .NET framework. In S. Vansummeren, editor, PODS 2006, page 706, Chicago, Illinois, June 2006.
[26]
H. Miller, P. Haller, E. Burmako, and M. Odersky. Object-oriented pickler combinators and an extensible generation framework, Mar. 2013. To appear.
[27]
U. Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology, 1997.
[28]
M. Odersky and A. Moors. Fighting bit rot with types (experience report: Scala collections). In FSTTCS 2009, December 15--17, 2009, IIT Kanpur, India, volume 4, pages 427--451, 2009.
[29]
E. Osheim. Spire, powerful new number types and numeric abstractions for scala. https://github.com/non/spire, 2013.
[30]
Postsharp Technologies. Producing high-quality software with aspect-oriented programming. Technical report, July 2011.
[31]
T. Rompf and M. Odersky. Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. ACM SIGPLAN Notices, 46(2):127--136, Feb. 2011.
[32]
T. Rompf, A. K. Sujeeth, K. J. Brown, H. Lee, H. Chafi, K. Olukotun, and M. Odersky. Project lancet: Surgical precision jit compilers, Mar. 2013. To appear.
[33]
M. Sabin. An exploration of generic/polytypic programming in scala. https://github.com/milessabin/shapeless, 2011.
[34]
D. Shabalin, E. Burmako, and M. Odersky. Quasiquotes for scala. Technical Report EPFL-REPORT-185242, EPFL, Lausanne, Switzerland, 2013.
[35]
T. Sheard and S. Peyton Jones. Template metaprogramming for Haskell. In ACM SIGPLAN Haskell Workshop 02, pages 1--16, Oct. 2002.
[36]
K. Skalski. Syntax-extending and type-reflecting macros in an object-oriented language. Master's thesis, University of Warsaw, Poland, 2005.
[37]
D. Syme, K. Battocchi, K. Takeda, D. Malayeri, J. Fisher, J. Hu, T. Liu, B. McNamara, D. Quirk, M. Taveggia, W. Chae, U. Matsveyeu, and T. Petricek. F# 3.0 - strongly-typed language support for internet-scale information sources. Technical Report MSR-TR-2012-101, Microsoft Research, september 2012.
[38]
W. Taha. Multi-Stage Programming: Its Theory and Applications. PhD thesis, Oregon Graduate Institute of Science and Technology, Portland, OR, 1999.
[39]
T. C. Team. The coq proof assistant. http://coq.inria.fr, 2012.
[40]
S. Tobin-Hochstadt, V. St-Amour, R. Culpepper, M. Flatt, and M. Felleisen. Languages as libraries. PLDI, 46(1993):132--141, 2010.
[41]
M. Torgersen. Asynchronous programming in c# and vb.net. Technical report, 2010.
[42]
Typesafe Inc. Scala language integrated connection kit. https://github.com/slick/slick, 2012.
[43]
Typesafe Inc. Akka. http://akka.io/, 2013.
[44]
Typesafe Inc. An asynchronous programming facility for scala. https://github.com/scala/async, 2013.
[45]
P. Voitot. Unveiling play 2.1 json api - bonus: Json inception (based on scala 2.10 macros). http://mandubian.com/2012/11/11/JSON-inception/, 2012.
[46]
P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In POPL, pages 60--76, 1989.
[47]
S. Weirich, B. A. Yorgey, J. Cretin, S. P. Jones, D. Vytiniotis, and J. P. Magalhaes. Giving haskell a promotion. Jan. 28 2012.
[48]
H. Zhang and S. Zdancewic. Fan: compile-time metaprogramming for ocaml, Apr. 2013. To appear.

Cited By

View all
  • (2024)Compiled, Extensible, Multi-language DSLs (Functional Pearl)Proceedings of the ACM on Programming Languages10.1145/36746278:ICFP(64-87)Online publication date: 15-Aug-2024
  • (2024)A Core Calculus for Documents: Or, Lambda: The Ultimate DocumentProceedings of the ACM on Programming Languages10.1145/36328658:POPL(667-694)Online publication date: 5-Jan-2024
  • (2023)MacoCaml: Staging Composable and Compilable MacrosProceedings of the ACM on Programming Languages10.1145/36078517:ICFP(604-648)Online publication date: 31-Aug-2023
  • Show More Cited By

Index Terms

  1. Scala macros: let our powers combine!: on how rich syntax and static types work with metaprogramming

    Recommendations

    Comments

    Please enable JavaScript to view thecomments powered by Disqus.

    Information & Contributors

    Information

    Published In

    cover image ACM Other conferences
    SCALA '13: Proceedings of the 4th Workshop on Scala
    July 2013
    84 pages
    ISBN:9781450320641
    DOI:10.1145/2489837
    Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

    Sponsors

    • CNRS: Centre National De La Rechercue Scientifique
    • UM2: University Montpellier 2
    • AITO: Assoc Internationale por les Technologies Objects

    In-Cooperation

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 02 July 2013

    Permissions

    Request permissions for this article.

    Check for updates

    Author Tags

    1. Scala
    2. compile-time metaprogramming
    3. domain-specific languages
    4. type classes

    Qualifiers

    • Research-article

    Conference

    ECOOP '13
    Sponsor:
    • CNRS
    • UM2
    • AITO

    Acceptance Rates

    SCALA '13 Paper Acceptance Rate 12 of 22 submissions, 55%;
    Overall Acceptance Rate 12 of 22 submissions, 55%

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)22
    • Downloads (Last 6 weeks)2
    Reflects downloads up to 14 Feb 2025

    Other Metrics

    Citations

    Cited By

    View all
    • (2024)Compiled, Extensible, Multi-language DSLs (Functional Pearl)Proceedings of the ACM on Programming Languages10.1145/36746278:ICFP(64-87)Online publication date: 15-Aug-2024
    • (2024)A Core Calculus for Documents: Or, Lambda: The Ultimate DocumentProceedings of the ACM on Programming Languages10.1145/36328658:POPL(667-694)Online publication date: 5-Jan-2024
    • (2023)MacoCaml: Staging Composable and Compilable MacrosProceedings of the ACM on Programming Languages10.1145/36078517:ICFP(604-648)Online publication date: 31-Aug-2023
    • (2022)Enhancing closures in scala 3 with spores3Proceedings of the Scala Symposium10.1145/3550198.3550428(22-27)Online publication date: 6-Jun-2022
    • (2022)Imperative or Functional Control Flow HandlingACM SIGMOD Record10.1145/3542700.354271551:1(60-67)Online publication date: 1-Jun-2022
    • (2022)ScalaEncyclopedia of Big Data Technologies10.1007/978-3-319-63962-8_306-3(1-5)Online publication date: 24-May-2022
    • (2021)Handling Iterations in Distributed Dataflow SystemsACM Computing Surveys10.1145/347760254:9(1-38)Online publication date: 8-Oct-2021
    • (2021)Virtual ADTs for portable metaprogrammingProceedings of the 18th ACM SIGPLAN International Conference on Managed Programming Languages and Runtimes10.1145/3475738.3480717(36-44)Online publication date: 29-Sep-2021
    • (2021)Concise, type-safe, and efficient structural diffingProceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation10.1145/3453483.3454052(406-419)Online publication date: 19-Jun-2021
    • (2021)The Power of Nested Parallelism in Big Data Processing – Hitting Three Flies with One Slap –Proceedings of the 2021 International Conference on Management of Data10.1145/3448016.3457287(605-618)Online publication date: 9-Jun-2021
    • Show More Cited By

    View Options

    Login options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Figures

    Tables

    Media

    Share

    Share

    Share this Publication link

    Share on social media