Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Javascript Options

JulianLeviston edited this page · 17 revisions
Clone this wiki locally

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, stronly 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!
Something went wrong with that request. Please try again.