Skip to main content

Sunroof: A Monadic DSL for Generating JavaScript

  • Conference paper
Practical Aspects of Declarative Languages (PADL 2014)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 8324))

Included in the following conference series:

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Similar content being viewed by others

References

  1. http://asmjs.org/

  2. http://taskjs.org/

  3. HTML Living Standard - Timers, http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#timers

  4. Apfelmus, H.: (2010), http://hackage.haskell.org/package/operational

  5. Apfelmus, H.: The Operational Monad Tutorial. The Monad. Reader 15, 37–55 (2010)

    Google Scholar 

  6. Ashkenas, J.: CoffeeScript, http://coffeescript.org/

  7. Bazerman, G.: JMacro, http://www.haskell.org/haskellwiki/Jmacro

  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. 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)

    Chapter  Google Scholar 

  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. Dijkstra, E.W.: Letters to the editor: go to statement considered harmful. Communications of the ACM 11(3), 147–148 (1968)

    Article  MathSciNet  Google Scholar 

  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)

    MATH  Google Scholar 

  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. Done, C., Bergmark, A.: Fay, https://github.com/faylang/fay/wiki

  15. Elliott, C.: Boolean, http://hackage.haskell.org/package/Boolean

  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. Gill, A.: Sunroof-active, https://github.com/ku-fpg/sunroof-active

  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. Gill, A.: (2013), http://hackage.haskell.org/package/blank-canvas

  20. Gill, A., Farmer, A.: Kansas Comet, http://hackage.haskell.org/package/kansas-comet

  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. 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)

    Chapter  Google Scholar 

  23. Leijen, D., Meijer, E.: Domain Specific Embedded Compilers. In: Domain-Specific Languages, pp. 109–122. ACM (1999)

    Google Scholar 

  24. Lin, C.: Programming Monads Operationally with Unimo. In: International Conference on Functional Programming, pp. 274–285. ACM (2006)

    Google Scholar 

  25. Mahemoff, M.: HTTP Streaming, http://ajaxpatterns.org/Comet

  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. Moggi, E.: Computational lambda-calculus and monads. In: Logic in Computer Science, pp. 14–23. IEEE Press (1989)

    Google Scholar 

  28. Murakami, S., Ashkenas, J.: LiveScript, http://livescript.net/

  29. Nazarov, V.: GHCJS Haskell to Javascript Compiler, https://github.com/ghcjs/ghcjs

  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)

    Chapter  Google Scholar 

  31. Predescu, O.: Model-View-Controller in Cocoon using continuations-based control flow (2002), http://www.webweavertech.com/ovidiu/weblog/archives/000042.html

  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)

    Chapter  Google Scholar 

  33. Finne, S., et al.: Calling hell from heaven and heaven from hell (1999)

    Google Scholar 

  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. 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. Stutterheim, J.: Improving the UHC JavaScript backend. Tech. rep., Utrecht University (2012), http://www.norm2782.com/improving-uhc-js-report.pdf

  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. Yorgey, B.: Active, https://github.com/diagrams/active

  39. Yorgey, B.: Active, https://github.com/diagrams

  40. Zakai, A.: Emscripten: An LLVM-to-Javascript Compiler, http://emscripten.org/

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2014 Springer International Publishing Switzerland

About this paper

Cite this paper

Bracker, J., Gill, A. (2014). Sunroof: A Monadic DSL for Generating JavaScript. In: Flatt, M., Guo, HF. (eds) Practical Aspects of Declarative Languages. PADL 2014. Lecture Notes in Computer Science, vol 8324. Springer, Cham. https://doi.org/10.1007/978-3-319-04132-2_5

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-04132-2_5

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-04131-5

  • Online ISBN: 978-3-319-04132-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics