Can GHCJS/Haste compile themselves?

820 Views Asked by At

If so, then I could let people play around with a project of mine by changing its (Haskell) configuration: recompiling it in the browser, and then rerunning it in the browser. I don't care about speed. I just want to be able to demo a hard-to-setup fundamentally-desktop project in the browser. So possible new users can see if they like it, within seconds and without setup.

How cool would that be!

from what I've read, GHCJS compiles STG into JavaScript. it says it uses the GHC API, so we should be able to compile that into JavaScript too, like any other Haskell library. (right?) Is it true that, while the GHC runtime has a lot of C, the compiler itself is pure Haskell?

so:

  1. Can GHCJS compile itself into JavaScript?
  2. Can Haste compile itself into JavaScript?
  3. Have either of these been done? (is that how http://haste-lang.org/try/ works? It seems to need a network.)
1

There are 1 best solutions below

4
sclv On

GHCJS and Haste both, to my knowledge, leverage GHC directly. GHC, though mainly haskell, is tied to a fair amount of cbits in terms of the runtime and how it operates. I am fairly certain neither can, at the moment, be compiled to run directly in browser in a "self-hosted" way.

However, Fay, which is a "Haskell-like-dialect" of JS can be compiled via GHCJS, which is pretty nifty (https://github.com/ghcjs/ghcjs-examples/tree/master/fay-hello) though perhaps not what you want.

Another alternative, if your system is simple enough, is to use emscripten to place hugs in-browser, and let your users play with that.

As you surmise, the various "try it in the browser" sites all actually use a connection to machines, typically running something like mueval that actually execute the code given.