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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
Notes
- 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.
We use \( JSString \) here so that the resulting Haskell record relates more closely to the JavaScript object.
- 3.
- 4.
References
UHC Git repository. https://github.com/UU-ComputerScience/uhc/
Haskell in web browser. http://www.haskell.org/haskellwiki/Haskell_in_web_browser (2007)
Yhc/Javascript. http://www.haskell.org/haskellwiki/Yhc/Javascript (2007)
A Haskell interpreter in JavaScript. https://github.com/johang88/haskellinjavascript (2010)
Clean. http://wiki.clean.cs.ru.nl/Clean (2011)
Apfelmus, H.: Reactive banana. http://www.haskell.org/haskellwiki/Reactive-banana
Ashkenas, J.: CoffeeScript. http://coffeescript.org/
Bruël, E., Jansen, J.M.: Implementing a non-strict purely Functional Language in JavaScript. In: Implementation of Functional Languages (2010)
Dijkstra, A., Fokker, J., Swierstra, S.D.: The Architecture of the Utrecht Haskell Compiler. In: Haskell Symposium (2009)
Dijkstra, A., Fokker, J., Swierstra, S.D.: UHC Utrecht Haskell Compiler. http://www.cs.uu.nl/wiki/UHC (2009)
Done, C.: Fay programming language. http://fay-lang.org/
ECMA International, Geneva, Switzerland. ECMAScript Language Specification. http://www.ecma-international.org/publications/standards/Ecma-262.htm (2011)
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
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)
Epstein, J., Black, A.P., PeytonJones, S.: Towards Haskell in the Cloud (2011)
Hofmann, M., Pierce, B., Wagner, D.: Symmetric lenses. SIGPLAN Not. 46(1), 371–384 (2011)
Jansen, J.M.: Functional web applications, implementation and use of client-side interpreters. Ph.D. thesis, Radboud University Nijmegen (2010)
Jones, S.P. (ed.): Haskell 98 Language and Libraries: The Revised Report. http://haskell.org/, September 2002
Kagawa, K.: Compositional references for stateful functional programming. SIGPLAN Not. 32(8), 217–226 (1997)
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)
Mackenzie, H., Nazarov, V., Stegeman, L.: GHCJS: Haskell to JavaScript translator. https://github.com/ghcjs/ghcjs/tree/gen2 (2012)
Miller, P., Graf, N., Schranz, T., Gerstmayr, A.: Brunch. IO. http://brunch.io/
Nazarov, V.: GHCJS: Haskell to Javascript compiler (via GHC). https://github.com/ghcjs/ghcjs (2011)
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)
Podolsky, O.: jquery-ajaxq. http://code.google.com/p/jquery-ajaxq/
Resig, J.: jQuery. http://jquery.com
Steele, O.: Functional JavaScript. http://osteele.com/sources/javascript/functional/ (2007)
Stutterheim, J., Swierstra, W., Swierstra, D.: Forty hours of declarative programming - Teaching Prolog at the Junior College Utrecht (2012)
Stutterheim, J., Vermeulen, A., Dijkstra, A.: UHC-JavaScript libraries. https://github.com/UU-ComputerScience/uhc-js
Swierstra, D., Stutterheim, J.: NanoProlog package. http://hackage.haskell.org/package/NanoProlog
Swierstra, W., Doaitse Swierstra, S., Stutterheim, J.: Logisch en Functioneel Programmeren voor Wiskunde D. Technical Report UU-CS-2011-033, Universiteit Utrecht (2011)
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)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights 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)