skip to main content
research-article

Layout-sensitive language extensibility with SugarHaskell

Published:13 September 2012Publication History
Skip Abstract Section

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.

References

  1. G. Bracha. Pluggable type systems. In OOPSLA Workshop on Revival of Dynamic Languages, 2004. Available at http://bracha.org/pluggableTypesPosition.pdf.Google ScholarGoogle Scholar
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. W. Clinger and J. Rees. Macros that work. In Proceedings of Symposium on Principles of Programming Languages (POPL), pages 155--162. ACM, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle Scholar
  10. GHC Team. The glorious Glasgow Haskell Compilation System user's guide, version 7.4.1, 2012.Google ScholarGoogle Scholar
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarCross RefCross Ref
  14. J. Hughes. Generalising monads to arrows. Science of Computer Programming, 37 (1-3): 67--111, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. D. E. Knuth. Semantics of context-free languages. Mathematical Systems Theory, 2 (2): 127--145, 1968.Google ScholarGoogle ScholarCross RefCross Ref
  17. P. J. Layzell. The history of macro processors in programming language extensibility. The Computer Journal, 28 (1): 29--33, 1985.Google ScholarGoogle ScholarCross RefCross Ref
  18. 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 ScholarGoogle Scholar
  19. G. Mainland. Why it's nice to be quoted: Quasiquoting for Haskell. In Proceedings of Haskell Workshop, pages 73--82. ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. S. Marlow (editor). Haskell 2010 language report. Available at http://www.haskell.org/onlinereport/haskell2010, 2010.Google ScholarGoogle Scholar
  21. C. McBride and R. Paterson. Applicative programming with effects. Journal of Functional Programming, 18 (1): 1--13, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. M. D. McIlroy. Macro instruction extensions of compiler languages. Communication of the ACM, 3 (4): 214--220, 1960. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. R. Paterson. A new notation for arrows. In Proceedings of International Conference on Functional Programming (ICFP), pages 229--240. ACM, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. R. Paterson and S. Peyton Jones. Type and translation rules for arrow notation in GHC, 2004.Google ScholarGoogle Scholar
  26. S. Priebe. Preprocessing Eden with Template Haskell. In Proceedings of Conference on Generative Programming and Component Engineering (GPCE), pages 357--372. Springer, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. F. Rieger. A language-independent framework for syntactic extensibility. Bachelor's Thesis, University of Marburg, June 2012. Submitted.Google ScholarGoogle Scholar
  28. T. Sheard and S. Peyton Jones. Template meta-programming for Haskell. In Proceedings of Haskell Workshop, pages 1--16. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  33. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  34. 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 ScholarGoogle Scholar

Index Terms

  1. Layout-sensitive language extensibility with SugarHaskell

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader
            About Cookies On This Site

            We use cookies to ensure that we give you the best experience on our website.

            Learn more

            Got it!