Skip to main content

Building JavaScript Applications with Haskell

  • Conference paper
  • First Online:
Implementation and Application of Functional Languages (IFL 2012)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 8241))

Included in the following conference series:

Abstract

We introduce the Utrecht Haskell Compiler JavaScript backend, which allows one to compile Haskell code to JavaScript, so it can be run in the browser. To interface with JavaScript and overcome part of the impedance mismatch between the two languages, we introduce the Foreign Expression Language; a small subset of JavaScript for use in Foreign Function Interface imports. Finally we discuss the implementation of a JavaScript application, completely written in Haskell, with which we show that it is now possible to write an entire JavaScript application completely in Haskell.

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 54.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 72.00
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

Notes

  1. 1.

    Naively using a Haskell \({ String }\) would give us a JavaScript representation of a list of characters, rather than a JavaScript string. To obtain a native JavaScript string, we require the Haskell \({ String }\) to be converted to a \( JSString \), which is a type synonym for \( PackedString \).

  2. 2.

    We use \( JSString \) here so that the resulting Haskell record relates more closely to the JavaScript object.

  3. 3.

    http://uu-computerscience.github.com/JCU/

  4. 4.

    https://github.com/UU-ComputerScience/uhc-js/tree/benchmark

References

  1. UHC Git repository. https://github.com/UU-ComputerScience/uhc/

  2. Haskell in web browser. http://www.haskell.org/haskellwiki/Haskell_in_web_browser (2007)

  3. Yhc/Javascript. http://www.haskell.org/haskellwiki/Yhc/Javascript (2007)

  4. A Haskell interpreter in JavaScript. https://github.com/johang88/haskellinjavascript (2010)

  5. Clean. http://wiki.clean.cs.ru.nl/Clean (2011)

  6. Apfelmus, H.: Reactive banana. http://www.haskell.org/haskellwiki/Reactive-banana

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

  8. Bruƫl, E., Jansen, J.M.: Implementing a non-strict purely Functional Language in JavaScript. In: Implementation of Functional Languages (2010)

    Google ScholarĀ 

  9. Dijkstra, A., Fokker, J., Swierstra, S.D.: The Architecture of the Utrecht Haskell Compiler. In: Haskell Symposium (2009)

    Google ScholarĀ 

  10. Dijkstra, A., Fokker, J., Swierstra, S.D.: UHC Utrecht Haskell Compiler. http://www.cs.uu.nl/wiki/UHC (2009)

  11. Done, C.: Fay programming language. http://fay-lang.org/

  12. ECMA International, Geneva, Switzerland. ECMAScript Language Specification. http://www.ecma-international.org/publications/standards/Ecma-262.htm (2011)

  13. Ekblad, A.: Towards a declarative web. Masterā€™s thesis, University of Gothenburg, Chalmers University of Technology, Department of Computer Science and Engineering, Gƶteborg, Sweden (2012) (To appear) http://ekblad.cc/hastereport.pdf

  14. Elliott, C.M.: Push-pull functional reactive programming. In: Proceedings of the 2nd ACM SIGPLAN Symposium on Haskell, Haskell ā€™09, pp. 25ā€“36. ACM, New York (2009)

    Google ScholarĀ 

  15. Epstein, J., Black, A.P., PeytonJones, S.: Towards Haskell in the Cloud (2011)

    Google ScholarĀ 

  16. Hofmann, M., Pierce, B., Wagner, D.: Symmetric lenses. SIGPLAN Not. 46(1), 371ā€“384 (2011)

    ArticleĀ  Google ScholarĀ 

  17. Jansen, J.M.: Functional web applications, implementation and use of client-side interpreters. Ph.D. thesis, Radboud University Nijmegen (2010)

    Google ScholarĀ 

  18. Jones, S.P. (ed.): Haskell 98 Language and Libraries: The Revised Report. http://haskell.org/, September 2002

  19. Kagawa, K.: Compositional references for stateful functional programming. SIGPLAN Not. 32(8), 217ā€“226 (1997)

    ArticleĀ  Google ScholarĀ 

  20. Leijen, D.: wxHaskell: A portable and concise GUI library for Haskell. In: Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell, Haskell ā€™04, pages 57ā€“68. ACM, New York (2004)

    Google ScholarĀ 

  21. Mackenzie, H., Nazarov, V., Stegeman, L.: GHCJS: Haskell to JavaScript translator. https://github.com/ghcjs/ghcjs/tree/gen2 (2012)

  22. Miller, P., Graf, N., Schranz, T., Gerstmayr, A.: Brunch. IO. http://brunch.io/

  23. Nazarov, V.: GHCJS: Haskell to Javascript compiler (via GHC). https://github.com/ghcjs/ghcjs (2011)

  24. Plasmeijer, R., Jansen, J.M., Koopman, P.: Declarative Ajax and Client Side Evaluation of Workflows using iTasks. In: Principles and Practice of Declarative Programming (2008)

    Google ScholarĀ 

  25. Podolsky, O.: jquery-ajaxq. http://code.google.com/p/jquery-ajaxq/

  26. Resig, J.: jQuery. http://jquery.com

  27. Steele, O.: Functional JavaScript. http://osteele.com/sources/javascript/functional/ (2007)

  28. Stutterheim, J., Swierstra, W., Swierstra, D.: Forty hours of declarative programming - Teaching Prolog at the Junior College Utrecht (2012)

    Google ScholarĀ 

  29. Stutterheim, J., Vermeulen, A., Dijkstra, A.: UHC-JavaScript libraries. https://github.com/UU-ComputerScience/uhc-js

  30. Swierstra, D., Stutterheim, J.: NanoProlog package. http://hackage.haskell.org/package/NanoProlog

  31. Swierstra, W., Doaitse Swierstra, S., Stutterheim, J.: Logisch en Functioneel Programmeren voor Wiskunde D. Technical Report UU-CS-2011-033, Universiteit Utrecht (2011)

    Google ScholarĀ 

  32. Wan, Z., Hudak, P.: Functional reactive programming from first principles. In: Proceedings of the ACM SIGPLAN 2000 Conference on Programming Language Design and Implementation, PLDI ā€™00, pp. 242ā€“252. ACM, New York (2000)

    Google ScholarĀ 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Atze Dijkstra .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

Ā© 2013 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Dijkstra, A., Stutterheim, J., Vermeulen, A., Swierstra, S.D. (2013). Building JavaScript Applications with Haskell. In: Hinze, R. (eds) Implementation and Application of Functional Languages. IFL 2012. Lecture Notes in Computer Science(), vol 8241. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-41582-1_3

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-41582-1_3

  • Published:

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-41581-4

  • Online ISBN: 978-3-642-41582-1

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics