Sunroof: A Monadic DSL for Generating JavaScript

  • Jan Bracker
  • Andy Gill
Part of the Lecture Notes in Computer Science book series (LNCS, volume 8324)

Abstract

Sunroof is a Haskell-hosted Domain Specific Language (DSL) for generating JavaScript. The central feature of Sunroof is a JavaScript monad, which, like the Haskell IO-monad, allows access to external resources, but specifically JavaScript resources. As such, Sunroof is primarily a feature-rich foreign-function API to the browser’s JavaScript engine, and all the browser-specific functionality, including HTML-based rendering, event handling, and drawing to the HTML5 canvas element.

In this paper, we give the design and implementation of Sunroof. Using monadic reification, we generate JavaScript from a deep embedding of the JavaScript monad. The Sunroof DSL has the feel of native Haskell, with a simple Haskell-based type schema to guide the Sunroof programmer. Furthermore, because we are generating code, we can offer Haskell-style concurrency patterns, such as MVars and Channels. In combination with a web-services package, the Sunroof DSL offers a robust platform to build interactive web applications.

Keywords

DSLs JavaScript Web Technologies Cloud Computing 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
    Apfelmus, H.: The Operational Monad Tutorial. The Monad. Reader 15, 37–55 (2010)Google Scholar
  6. 6.
    Ashkenas, J.: CoffeeScript, http://coffeescript.org/
  7. 7.
  8. 8.
    Chakravarty, M.M.T., Keller, G., Peyton Jones, S.: Associated type synonyms. In: International Conference on Functional Programming, pp. 241–253. ACM (2005)Google Scholar
  9. 9.
    Cooper, E., Lindley, S., Wadler, P., Yallop, J.: Links: Web Programming Without Tiers. In: de Boer, F.S., Bonsangue, M.M., Graf, S., de Roever, W.-P. (eds.) FMCO 2006. LNCS, vol. 4709, pp. 266–296. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  10. 10.
    Dijkstra, A., Stutterheim, J., Vermeulen, A., Swierstra, S.: Building JavaScript applications with Haskell. In: Hinze, R. (ed.) IFL 2012. LNCS, vol. 8241, pp. 37–52. Springer, Heidelberg (2013)Google Scholar
  11. 11.
    Dijkstra, E.W.: Letters to the editor: go to statement considered harmful. Communications of the ACM 11(3), 147–148 (1968)CrossRefMathSciNetGoogle Scholar
  12. 12.
    Domoszlai, L., Bruël, E., Jansen, J.M.: Implementing a non-strict purely functional language in JavaScript. Acta Universitatis Sapientiae 3, 76–98 (2011)MATHGoogle Scholar
  13. 13.
    Domoszlai, L., Plasmeijer, R.: Compiling Haskell to JavaScript through Clean’s core. In: Selected papers of 9th Joint Conference on Mathematics and Computer Science (February 2012)Google Scholar
  14. 14.
    Done, C., Bergmark, A.: Fay, https://github.com/faylang/fay/wiki
  15. 15.
  16. 16.
    Farmer, A., Gill, A.: Haskell DSLs for Interactive Web Services. In: First Workshop on Cross-model Language Design and Implementation (2012)Google Scholar
  17. 17.
    Gill, A.: Sunroof-active, https://github.com/ku-fpg/sunroof-active
  18. 18.
    Gill, A.: Type-Safe Observable Sharing in Haskell. In: Proceedings of the Second ACM SIGPLAN Haskell Symposium, Haskell 2009, pp. 117–128 (September 2009)Google Scholar
  19. 19.
  20. 20.
    Gill, A., Farmer, A.: Kansas Comet, http://hackage.haskell.org/package/kansas-comet
  21. 21.
    Jones, S.P., Gordon, A., Finne, S.: Concurrent Haskell. In: Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, vol. 21, pp. 295–308 (1996)Google Scholar
  22. 22.
    Kossakowski, G., Amin, N., Rompf, T., Odersky, M.: JavaScript as an Embedded DSL. In: Noble, J. (ed.) ECOOP 2012. LNCS, vol. 7313, pp. 409–434. Springer, Heidelberg (2012)CrossRefGoogle Scholar
  23. 23.
    Leijen, D., Meijer, E.: Domain Specific Embedded Compilers. In: Domain-Specific Languages, pp. 109–122. ACM (1999)Google Scholar
  24. 24.
    Lin, C.: Programming Monads Operationally with Unimo. In: International Conference on Functional Programming, pp. 274–285. ACM (2006)Google Scholar
  25. 25.
    Mahemoff, M.: HTTP Streaming, http://ajaxpatterns.org/Comet
  26. 26.
    Mainland, G.: Why It’s Nice to be Quoted: Quasiquoting for Haskell. In: Proceedings of the ACM SIGPLAN Haskell Workshop, Haskell 2007, New York, NY, USA, pp. 73–82 (2007)Google Scholar
  27. 27.
    Moggi, E.: Computational lambda-calculus and monads. In: Logic in Computer Science, pp. 14–23. IEEE Press (1989)Google Scholar
  28. 28.
    Murakami, S., Ashkenas, J.: LiveScript, http://livescript.net/
  29. 29.
    Nazarov, V.: GHCJS Haskell to Javascript Compiler, https://github.com/ghcjs/ghcjs
  30. 30.
    Persson, A., Axelsson, E., Svenningsson, J.: Generic monadic constructs for embedded languages. In: Gill, A., Hage, J. (eds.) IFL 2011. LNCS, vol. 7257, pp. 85–99. Springer, Heidelberg (2012)CrossRefGoogle Scholar
  31. 31.
    Predescu, O.: Model-View-Controller in Cocoon using continuations-based control flow (2002), http://www.webweavertech.com/ovidiu/weblog/archives/000042.html
  32. 32.
    Rompf, T., Odersky, M.: Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. In: Proceedings of the Ninth International Conference on Generative Programming and Component Engineering, GPCE 2010, pp. 127–136. ACM, New York (2010)CrossRefGoogle Scholar
  33. 33.
    Finne, S., et al.: Calling hell from heaven and heaven from hell (1999)Google Scholar
  34. 34.
    Sculthorpe, N., Bracker, J., Giorgidze, G., Gill, A.: The Constrained-Monad Problem. In: International Conference on Functional Programming, pp. 287–298. ACM (2013)Google Scholar
  35. 35.
    Shields, M., Peyton Jones, S.: Object-oriented style overloading for Haskell. In: First Workshop on Multi-Language Inferastructure and Interoperability (BABEL 2001), Firenze, Italy (September 2001)Google Scholar
  36. 36.
    Stutterheim, J.: Improving the UHC JavaScript backend. Tech. rep., Utrecht University (2012), http://www.norm2782.com/improving-uhc-js-report.pdf
  37. 37.
    Svenningsson, J., Svensson, B.J.: Simple and compositional reification of monadic embedded languages. In: International Conference on Functional Programming, pp. 299–304. ACM (2013)Google Scholar
  38. 38.
  39. 39.
    Yorgey, B.: Active, https://github.com/diagrams
  40. 40.
    Zakai, A.: Emscripten: An LLVM-to-Javascript Compiler, http://emscripten.org/

Copyright information

© Springer International Publishing Switzerland 2014

Authors and Affiliations

  • Jan Bracker
    • 1
  • Andy Gill
    • 2
  1. 1.Institut für InformatikChristian-Albrechts-UniversitätKielGermany
  2. 2.ITTC / EECSThe University of KansasLawrenceUSA

Personalised recommendations