[Haskell-cafe] ghci & ghc -> JS (Emscripten)

Luite Stegeman stegeman at gmail.com
Fri Jun 28 17:01:00 CEST 2013

I don't know of any complete implementation. The LLVM code produced by GHC
might be hard to compile to JavaScript, since JS does not have tail call
optimization. You would also need to get the RTS working, including the
garbage collector. It's written in C and Cmm, both of which can be compiled
to LLVM, but often in practice it's not that easy to get it working

We do have a working Haskell compiler based on GHC with GHCJS [1], which
uses the GHC API to translate STG code to JavaScript. We do a fairly
high-level translation, compiling Haskell closures to JavaScript objects,
so that we use as much of the JS runtime, like the garbage collector, as
possible. I have spent some time optimizing the performance, making sure
that the code is reasonably optimizable by the JS JIT compilers, makes
effective use of the inline caches etc, but it's quite possible that a
lower level LLVM/asm.js would give us better performance.

For the moment though, we want to concentrate on other things, like getting
a release ready before GHC 7.8.1 is out (and getting the patches to support
GHCJS merged in GHC), building more libraries, and reducing the size of the
generated code.

Dan Frumin [2] is working for his Google Summer of Code project on an
pastebin that uses GHCJS and the diagrams [3] library that lets the user
run the code directly. Generated code supports graphics, functional
reactive programming etc, and can be included on other pages. Code is
compiled on the server, since GHC itself is a bit too big to compile to

For more information on GHCJS, see my weblog [4] [5]. In the past we have
already had multiple code generators, if you want to work on one that uses
LLVM as the source language we would be happy to add it, and you can use
the GHCJS Cabal support, testsuite etc. If it's clearly better than the
existing one, it can replace it one day as the default generator.


[1] GHCJS: https://github.com/ghcjs
[2] Dan Frumin's weblog: http://parenz.wordpress.com/
[3] Diagrams library: http://hackage.haskell.org/package/diagrams
[4] GHCJS introduction: http://weblog.luite.com/wordpress/?p=14
[5] Functional Reactive Programming with GHCJS and sodium:

On Fri, Jun 28, 2013 at 3:25 PM, B B <blackbox.dev.ml at gmail.com> wrote:

> Hi!
> Does anybody tried, or is there anywhere a project, of online ghc or ghci
> (compiled to JavaScript with Emscripten)?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130628/be3a27e0/attachment.htm>

More information about the Haskell-Cafe mailing list