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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
HTML Living Standard - Timers, http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#timers
Apfelmus, H.: (2010), http://hackage.haskell.org/package/operational
Apfelmus, H.: The Operational Monad Tutorial. The Monad. Reader 15, 37–55 (2010)
Ashkenas, J.: CoffeeScript, http://coffeescript.org/
Bazerman, G.: JMacro, http://www.haskell.org/haskellwiki/Jmacro
Chakravarty, M.M.T., Keller, G., Peyton Jones, S.: Associated type synonyms. In: International Conference on Functional Programming, pp. 241–253. ACM (2005)
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)
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)
Dijkstra, E.W.: Letters to the editor: go to statement considered harmful. Communications of the ACM 11(3), 147–148 (1968)
Domoszlai, L., Bruël, E., Jansen, J.M.: Implementing a non-strict purely functional language in JavaScript. Acta Universitatis Sapientiae 3, 76–98 (2011)
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)
Done, C., Bergmark, A.: Fay, https://github.com/faylang/fay/wiki
Elliott, C.: Boolean, http://hackage.haskell.org/package/Boolean
Farmer, A., Gill, A.: Haskell DSLs for Interactive Web Services. In: First Workshop on Cross-model Language Design and Implementation (2012)
Gill, A.: Sunroof-active, https://github.com/ku-fpg/sunroof-active
Gill, A.: Type-Safe Observable Sharing in Haskell. In: Proceedings of the Second ACM SIGPLAN Haskell Symposium, Haskell 2009, pp. 117–128 (September 2009)
Gill, A.: (2013), http://hackage.haskell.org/package/blank-canvas
Gill, A., Farmer, A.: Kansas Comet, http://hackage.haskell.org/package/kansas-comet
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)
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)
Leijen, D., Meijer, E.: Domain Specific Embedded Compilers. In: Domain-Specific Languages, pp. 109–122. ACM (1999)
Lin, C.: Programming Monads Operationally with Unimo. In: International Conference on Functional Programming, pp. 274–285. ACM (2006)
Mahemoff, M.: HTTP Streaming, http://ajaxpatterns.org/Comet
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)
Moggi, E.: Computational lambda-calculus and monads. In: Logic in Computer Science, pp. 14–23. IEEE Press (1989)
Murakami, S., Ashkenas, J.: LiveScript, http://livescript.net/
Nazarov, V.: GHCJS Haskell to Javascript Compiler, https://github.com/ghcjs/ghcjs
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)
Predescu, O.: Model-View-Controller in Cocoon using continuations-based control flow (2002), http://www.webweavertech.com/ovidiu/weblog/archives/000042.html
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)
Finne, S., et al.: Calling hell from heaven and heaven from hell (1999)
Sculthorpe, N., Bracker, J., Giorgidze, G., Gill, A.: The Constrained-Monad Problem. In: International Conference on Functional Programming, pp. 287–298. ACM (2013)
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)
Stutterheim, J.: Improving the UHC JavaScript backend. Tech. rep., Utrecht University (2012), http://www.norm2782.com/improving-uhc-js-report.pdf
Svenningsson, J., Svensson, B.J.: Simple and compositional reification of monadic embedded languages. In: International Conference on Functional Programming, pp. 299–304. ACM (2013)
Yorgey, B.: Active, https://github.com/diagrams/active
Yorgey, B.: Active, https://github.com/diagrams
Zakai, A.: Emscripten: An LLVM-to-Javascript Compiler, http://emscripten.org/
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)