Skip to content
Tobias Vetter edited this page Oct 14, 2018 · 2 revisions

Yesod by default gives you Shakespearean JavaScript, also known as Julius. It is just JavaScript that you can insert Haskell (JSON) values into. Also Shakespearean Coffee and Shakespearean Typescript. Coffeescript is a thin veneer that papers over JavaScript to make a convenient and consistent language, but there is still no type system. TypeScript adds a type system and compiles down the latest JavaScript standard to an older version. It is likely the easiest way to get some types into your JavaScript, although its type system does allow anything to be null.

There is prior art for Julius: jmacro has QQ value insertion, but also supports a haskell-ish version of JavaScript.

Using JavaScript Frameworks

The most robust and portable approach is to use one of the above JavaScript template tools and integrate with an existing JavaScript framework.

Compile Haskell

Fay is a new alternative that we would love to hear some experience reports about.

  • Fay, Haskell code translated to JS. Upside: produces a small amount of understandable JavaScript. Downside: only a subset of Haskell is supported.
  • UHC js compiler. Downsides: alpha, not completely integrated with cabal, not GHC.
  • ghcjs - example Yesod app - directly compile ghc core to JavaScript. Downside: produces large amounts of JavaScript.
  • PureScript - small, strongly typed, very similar to Haskell. Downside: not actually Haskell. Maybe worth looking at Purescript Virtual DOM , similar FRP-style thing to ReactJS.

Alternative experimental ways to compile Haskell

  • Emscripten — compiles LLVM/Clang output to JavaScript. If you use features of the GHC runtime you also have to compile it, which nobody has made an effort to figure out.
  • PNaCL - run native code on Google Chrome with NaCL. PNaCL is the next generation that will run LLVM byte code. Won't work on other browsers.
  • JS Haskell interpreter

A Haskell-like language that only compiles to JavaScript

We would really like to hear about your experience with Elm or Roy, which are 2 nice options with Yesod integration.

  • Elm - Yesod integration available. Haskell inspired language that also offers an FRP GUI. Downside: not quite Haskell, not JavaScript.
  • Roy - Yesod integration (Roy templates) available. JavaScripty semantics with Haskelly features. Project is starting to mature. Upside: should be easier to use with existing JS than many other alternatives. Downside: not Haskell.
  • lambdascript
  • Forml - Haskell-inspired syntax & type safety with Ruby-inspired expresiveness

Haskell code that explicitly generates JavaScript

  • Reactive-banana - an FRP GUI framework can now output html/JavaScript
  • Panther-Ajax Experimental library to write server side code that accesses the dom and uses continuations.
  • Ji - experimental library not currently working with Yesod. Same as Panther-Ajax, but under active development.
  • HJScript - JavaScript DSL.
  • yesod-js - currently stalled while investigating Fay/Elm/ghc-js

Other strongly typed functional languages that compile to JavaScript

  • Ur/Web - A Haskell-like programming language tailored to web programming. Automatically generates FRP JavaScript code. Appropriate for taking the FRP plunge, but Heavyweight (large library and difficult to debug) if you just want some strongly-typed JS. Opa is a very similar concept.
  • JS of OCaml - There is also an in-browser OCaml bytecode interpreter!
Clone this wiki locally