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:

  • 742 Accesses

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

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Similar content being viewed by others

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