Abstract
Programmers need convenient syntax to write elegant and concise programs. Consequently, the Haskell standard provides syntactic sugar for some scenarios (e.g., do notation for monadic code), authors of Haskell compilers provide syntactic sugar for more scenarios (e.g., arrow notation in GHC), and some Haskell programmers implement preprocessors for their individual needs (e.g., idiom brackets in SHE). But manually written preprocessors cannot scale: They are expensive, error-prone, and not composable. Most researchers and programmers therefore refrain from using the syntactic notations they need in actual Haskell programs, but only use them in documentation or papers. We present a syntactically extensible version of Haskell, SugarHaskell, that empowers ordinary programmers to implement and use custom syntactic sugar.
Building on our previous work on syntactic extensibility for Java, SugarHaskell integrates syntactic extensions as sugar libraries into Haskell's module system. Syntax extensions in SugarHaskell can declare arbitrary context-free and layout-sensitive syntax. SugarHaskell modules are compiled into Haskell modules and further processed by a Haskell compiler. We provide an Eclipse-based IDE for SugarHaskell that is extensible, too, and automatically provides syntax coloring for all syntax extensions imported into a module.
We have validated SugarHaskell with several case studies, including arrow notation (as implemented in GHC) and EBNF as a concise syntax for the declaration of algebraic data types with associated concrete syntax. EBNF declarations also show how to extend the extension mechanism itself: They introduce syntactic sugar for using the declared concrete syntax in other SugarHaskell modules.
- G. Bracha. Pluggable type systems. In OOPSLA Workshop on Revival of Dynamic Languages, 2004. Available at http://bracha.org/pluggableTypesPosition.pdf.Google Scholar
- M. Bravenboer, R. Vermaas, J. J. Vinju, and E. Visser. Generalized type-based disambiguation of meta programs with concrete object syntax. In Proceedings of Conference on Generative Programming and Component Engineering (GPCE), volume 3676 of LNCS, pages 157--172. Springer, 2005. Google Scholar
Digital Library
- W. Clinger and J. Rees. Macros that work. In Proceedings of Symposium on Principles of Programming Languages (POPL), pages 155--162. ACM, 1991. Google Scholar
Digital Library
- A. Dijkstra, J. Fokker, and S. D. Swierstra. The architecture of the Utrecht Haskell compiler. In Proceedings of Haskell Symposium, pages 93--104. ACM, 2009. Google Scholar
Digital Library
- T. Ekman and G. Hedin. The JastAdd extensible Java compiler. In Proceedings of Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pages 1--18. ACM, 2007. Google Scholar
Digital Library
- S. Erdweg, L. C. L. Kats, T. Rendel, C. Kästner, K. Ostermann, and E. Visser. Growing a language environment with editor libraries. In Proceedings of Conference on Generative Programming and Component Engineering (GPCE), pages 167--176. ACM, 2011a. Google Scholar
Digital Library
- S. Erdweg, T. Rendel, C. Kästner, and K. Ostermann. SugarJ: Library-based syntactic language extensibility. In Proceedings of Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pages 391--406. ACM, 2011b. Google Scholar
Digital Library
- S. Erdweg, P. G. Giarrusso, and T. Rendel. Language composition untangled. In Proceedings of Workshop on Language Descriptions, Tools and Applications (LDTA), 2012a. to appear. Google Scholar
Digital Library
- S. Erdweg, T. Rendel, C. Kästner, and K. Ostermann. Layout-sensitive generalized parsing. Submitted to Conference on Software Language Engineering (SLE), June 2012b. Draft available at http://sugarj.org/layout-parsing.pdf.Google Scholar
- GHC Team. The glorious Glasgow Haskell Compilation System user's guide, version 7.4.1, 2012.Google Scholar
- B. Heeren, J. Hage, and S. D. Swierstra. Scripting the type inference process. In Proceedings of International Conference on Functional Programming (ICFP), pages 3--13. ACM, 2003. Google Scholar
Digital Library
- J. Heering, P. R. H. Hendriks, P. Klint, and J. Rekers. The syntax definition formalism SDF - reference manual. SIGPLAN Notices, 24 (11): 43--75, 1989. Google Scholar
Digital Library
- Z. Hemel, L. C. L. Kats, D. M. Groenewegen, and E. Visser. Code generation by model transformation: A case study in transformation modularity. Software and System Modeling, 9 (3): 375--402, 2010.Google Scholar
Cross Ref
- J. Hughes. Generalising monads to arrows. Science of Computer Programming, 37 (1-3): 67--111, 2000. Google Scholar
Digital Library
- L. C. L. Kats and E. Visser. The Spoofax language workbench: Rules for declarative specification of languages and IDEs. In Proceedings of Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pages 444--463. ACM, 2010. Google Scholar
Digital Library
- D. E. Knuth. Semantics of context-free languages. Mathematical Systems Theory, 2 (2): 127--145, 1968.Google Scholar
Cross Ref
- P. J. Layzell. The history of macro processors in programming language extensibility. The Computer Journal, 28 (1): 29--33, 1985.Google Scholar
Cross Ref
- D. Leijen and E. Meijer. Parsec: Direct style monadic parser combinators for the real world. Technical Report UU-CS-2001-27, Universiteit Utrecht, 2001.Google Scholar
- G. Mainland. Why it's nice to be quoted: Quasiquoting for Haskell. In Proceedings of Haskell Workshop, pages 73--82. ACM, 2007. Google Scholar
Digital Library
- S. Marlow (editor). Haskell 2010 language report. Available at http://www.haskell.org/onlinereport/haskell2010, 2010.Google Scholar
- C. McBride and R. Paterson. Applicative programming with effects. Journal of Functional Programming, 18 (1): 1--13, 2008. Google Scholar
Digital Library
- M. D. McIlroy. Macro instruction extensions of compiler languages. Communication of the ACM, 3 (4): 214--220, 1960. Google Scholar
Digital Library
- N. Nystrom, M. R. Clarkson, and A. C. Myers. Polyglot: An extensible compiler framework for Java. In Proceedings of Conference on Compiler Construction (CC), volume 2622 of LNCS, pages 138--152. Springer, 2003. Google Scholar
Digital Library
- R. Paterson. A new notation for arrows. In Proceedings of International Conference on Functional Programming (ICFP), pages 229--240. ACM, 2001. Google Scholar
Digital Library
- R. Paterson and S. Peyton Jones. Type and translation rules for arrow notation in GHC, 2004.Google Scholar
- S. Priebe. Preprocessing Eden with Template Haskell. In Proceedings of Conference on Generative Programming and Component Engineering (GPCE), pages 357--372. Springer, 2005. Google Scholar
Digital Library
- F. Rieger. A language-independent framework for syntactic extensibility. Bachelor's Thesis, University of Marburg, June 2012. Submitted.Google Scholar
- T. Sheard and S. Peyton Jones. Template meta-programming for Haskell. In Proceedings of Haskell Workshop, pages 1--16. ACM, 2002. Google Scholar
Digital Library
- M. Sperber, R. K. Dybvig, M. Flatt, A. van Straaten, R. Findler, and J. Matthews. Revised6 report on the algorithmic language Scheme. Journal of Functional Programming, 19 (Supplement S1): 1--301, 2009. Google Scholar
Digital Library
- S. Tobin-Hochstadt, V. St-Amour, R. Culpepper, M. Flatt, and M. Felleisen. Languages as libraries. In Proceedings of Conference on Programming Language Design and Implementation (PLDI). ACM, 2011. Google Scholar
Digital Library
- E. Van Wyk, D. Bodin, J. Gao, and L. Krishnan. Silver: An extensible attribute grammar system. Science of Computer Programming, 75 (1-2): 39--54, 2010. Google Scholar
Digital Library
- E. Visser. Stratego: A language for program transformation based on rewriting strategies. In Proceedings of Conference on Rewriting Techniques and Applications (RTA), volume 2051 of LNCS, pages 357--362. Springer, 2001. Google Scholar
Digital Library
- E. Visser. Meta-programming with concrete object syntax. In Proceedings of Conference on Generative Programming and Component Engineering (GPCE), volume 2487 of LNCS, pages 299--315. Springer, 2002. Google Scholar
Digital Library
- M. Voelter and K. Solomatov. Language modularization and composition with projectional language workbenches illustrated with MPS. http://voelter.de/data/pub/VoelterSolomatov_SLE2010_LanguageModularizationAndCompositionLWBs.pdf, 2010.Google Scholar
Index Terms
Layout-sensitive language extensibility with SugarHaskell
Recommendations
Layout-sensitive language extensibility with SugarHaskell
Haskell '12: Proceedings of the 2012 Haskell SymposiumProgrammers need convenient syntax to write elegant and concise programs. Consequently, the Haskell standard provides syntactic sugar for some scenarios (e.g., do notation for monadic code), authors of Haskell compilers provide syntactic sugar for more ...
SugarJ: library-based syntactic language extensibility
OOPSLA '11: Proceedings of the 2011 ACM international conference on Object oriented programming systems languages and applicationsExisting approaches to extend a programming language with syntactic sugar often leave a bitter taste, because they cannot be used with the same ease as the main extension mechanism of the programming language - libraries. Sugar libraries are a novel ...
SugarJ: library-based syntactic language extensibility
OOPSLA '11Existing approaches to extend a programming language with syntactic sugar often leave a bitter taste, because they cannot be used with the same ease as the main extension mechanism of the programming language - libraries. Sugar libraries are a novel ...







Comments