GHCJS supports many modern Haskell features, including:
- All type system extensions supported by GHC
- Lightweight preemptive threading with blackholes, MVar, STM, asynchronous exceptions
- Weak references, CAF deallocation, StableName, StablePtr
- Unboxed arrays, emulated pointers
- Integer support through JSBN, 32 and 64 bit signed and unsigned arithmetic (
- Cost-centres, stack traces
- Cabal support, GHCJS has its own package database
- synchronous and asynchronous threads.
GHCJS can be installed with GHC 7.8.2 or later.
- GHC 7.8.2 or higher
- Cabal 1.22 and cabal-install 1.22 or higher
- alex and happy
- node.js 0.10.28 or higher. GHCJS uses node.js for its build system and for running Template Haskell.
Linux / OS X
- A recent version of
happyneed to be in your
autoreconfneed to be in your
- One of the dependencies is the
terminfoHaskell package, which requires
libtinfo. On Debian/Ubuntu this is provided by the
- You need a shell that's capable of running autotools scripts (with
autoreconfinstalled). See the GHCJS Wiki or the
INSTALL.windowsfile for instructions for setting up MSYS2 for this.
- A recent version of
happyneed to be in your
- Virus scanners often interfere with configure scripts (permission denied errors),
disable on-access scanning before running
If you use GHC 7.8, you need to update your
Cabal to version 1.22 to be able to use
GHCJS. GHC 7.10 already includes a compatible
Cabal version. Cabal support has been
merged upstream, get the correct version from https://github.com/haskell/cabal or from
Hackage once it has been released.
Note that you need a compatible
Cabal library in your GHC package database, just upgrading
cabal-install program is not enough.
ghcjs-boot will complain if it finds an incompatible
Make sure that you're now running the updated
GHCJS support must be listed under the
$ cabal install --help ... build files (default dist) -g --ghc compile with GHC --ghcjs compile with GHCJS --nhc98 compile with NHC ...
ghcjs and its
$ git clone https://github.com/ghcjs/ghcjs-prim.git $ git clone https://github.com/ghcjs/ghcjs.git $ cabal install ./ghcjs ./ghcjs-prim
cabal install ./ghcjs ./ghcjs-prim fails because cabal cannot resolve dependencies, try adding
--reorder-goals --max-backjumps=-1. Sometimes the
transformers package causes problems, since GHC ships with an older version. Try
--constraint=transformers==0.3.0.0 (or the version that came with your GHC) if the problem looks related to this package.
Build the libraries
ghcjs-boot to build the base libraries for
if you used the Git repository to install: $ ghcjs-boot --dev if you are doing a development build with GHC 7.10, you need to tell `ghcjs-boot` to use the `ghc-7.10` branch of the `ghcjs-boot` repository: $ ghcjs-boot --dev --ghcjs-boot-dev-branch ghc-7.10 if you are using a package from hackage that includes the libraries: $ ghcjs-boot
Some distros install node.js as
nodejs instead of
--with-node nodejs to the
ghcjs-boot command in that case.
$ ghcjs -o helloWorld helloWorld.hs $ node helloWorld.jsexe/all.js Hello world!
cabal install --ghcjs packageName to install a package
You can use Cabal sandboxes with GHCJS, create a new sandbox with:
$ cabal sandbox init
Then you can just configure with
--ghcjs to build with GHCJS inside the sandbox:
$ cabal install --ghcjs
If you also want to set GHCJS as the default compiler in the sandbox, run:
$ cabal sandbox init $ echo "compiler: ghcjs" >> cabal.config
Setting the default compiler to
cabal sandbox exec and
cabal sandbox hc-pkg use
GHCJS-specific settings. These commands do not know about the configure flags, so setting the default
compiler is the only way to make them use the correct settings for GHCJS.
ghcjs-pkg to manipulate the GHCJS package database
The package database and runtime files from the shims repository are kept in the
GHCJS application data directory, typically
~/.ghcjs/. Remove this directory to reset your GHCJS installation, you
will need to run
ghcjs-boot --init again.
See GHCJS introduction for more examples.
If you want to hack on GHCJS, please join our friendly community on IRC at
#ghcjs on freenode (You're also
welcome if you only use the compiler or just want to chat about it!). Read the HACKING.markdown document
to get started. The wiki may also contain useful information.
JSC and webkit
- webkit - Bindings for WebKitGTK+ that provide a low level DOM interface.
You can use these libraries without GHCJS to build a native version of your application (it will use WebKitGTK+ to run without a browser). If you want to find out more about making GHCJS compatible Haskell applications check out the GHCJS Examples