UHC-like JavaScript backend in GHC

Luite Stegeman stegeman at gmail.com
Tue Nov 13 19:08:04 CET 2012

On Mon, Nov 12, 2012 at 9:16 AM, Jurriën Stutterheim
<j.stutterheim at me.com> wrote:
> Hi all,
>   foreign import js "%1.push(%2)"
>     push :: JSArray a -> a -> IO (JSArray a)

I'm not sure if it's even necessary to extend GHC itself for this.
Even though this exact syntax (with the js calling convention name) is
not supported, the import pattern is available as a string at compile
time [1], so you can easily generate the desired code with a compiler
that uses the GHC API. I work on GHCJS [2], a compiler that generates
Javascript from STG.

Unfortunately, GHCJS is in a state of flux at the moment so it's a bit
hard to come up with a proof of concept implementation at this point.
I started a complete rewrite a few months ago, because the old version
didn't have the performance I needed. The new version [3] appears to
generate much faster code, but a lot of things (including FFI) have
not yet been implemented. It's still a bit too early to tell if the
new code generator can fully replace the old one.

I would like to add the friendlier FFI syntax later, but as far as i
can see, it should be pretty straightforward to do this... (at least
compared to supporting many of the other GHC features in JS)

WebWorkers might not be able to do what you need for concurrency,
since the ways you can communicate between them are really limited,
you have to serialize everything, no shared data. This is why GHCJS
has its own scheduler [4] in the RTS.


[1] http://www.haskell.org/ghc/docs/7.6.1/html/libraries/ghc-7.6.1/ForeignCall.html#t:ForeignCall
[2] GHCJS - https://github.com/ghcjs/ghcjs
[3] GHCJS new code generator - https://github.com/ghcjs/ghcjs/tree/gen2
[4] GHCJS scheduler -

More information about the Glasgow-haskell-users mailing list