Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can GHCJS/Haste compile themselves?

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.)
like image 507
sam boosalis Avatar asked Jan 16 '15 06:01

sam boosalis


People also ask

What is the use of ghcjs in Haskell?

GHCJS is a Haskell to JavaScript compiler that uses the GHC API. GHCJS contains a library, ghcjs, which contains the JavaScript code generator and a slightly customized variant of the ghc library, and several executable programs. The repository has several submodules and some files must be generated before the package can be installed.

What is ghcjs?

GHCJS is a Haskell to JavaScript compiler that uses the GHC API. Quick Start - Developing GHCJS GHCJS contains a library, ghcjs, which contains the JavaScript code generator and a slightly customized variant of the ghc library, and several executable programs.

How do I install a specific ghcjs package?

GHCJS depends on a few "local" packages in the source tree. You can use cabal-install and stack to set up a build environment that contains these packages. After the source tree has been prepared, the package can be installed. You may want ensure that binaries of earlier versions are overwritten:

What does ghcjs-boot do?

The ghcjs-boot program builds the "boot" libraries, like ghc-prim, base and template-haskell with GHCJS. After booting, GHCJS can compile regular Haskell programs and packages. ghcjs-boot needs to be able to find the emscripten toolchain, a nodejs executable.


1 Answers

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.

like image 197
sclv Avatar answered Oct 16 '22 03:10

sclv