
GHCJS - Haskell in the Browser - wtetzner
http://weblog.luite.com/wordpress/?p=14&date=2013-06-03
======
joeyh
There's also Fay
<[https://github.com/faylang/fay/wiki>](https://github.com/faylang/fay/wiki>)
which provides a lighter-weight compilation of Haskell to JS, omitting stuff
like threading and type classes.

Nice thing about Fay is you can read the generated javascript and see the 1:1
correspondance to the haskell code. This can be a nice way to get an intuition
abvout how thunks are used to implement eg, infinite length lazy lists in
haskell. There is also a live IDE <[http://ide.fay-lang.org/>](http://ide.fay-
lang.org/>). I think this makes Fay an excellent teaching tool.

The way it seems to be shaping up is that ghcjs will be used for big serious
projects where a javascript runtime that is measured in (IIRC) megabytes is
acceptable and the full power of haskell is needed. While fay will be used as
glue code for projects that are mostly written in server side Haskell and want
to run some code in the browser, with access to the same types used on sever-
side to eg, make AJAX nicer. Fay's entire runtime is 16 kb (unminified; with
minification and other size optimisations a complete program can be as small
as 3 kb)
<[https://github.com/faylang/fay/blob/master/js/runtime.js>](https://github.com/faylang/fay/blob/master/js/runtime.js>)
which makes it work well in these niches.

~~~
swannodette
It's been quite exciting to see all this activity around functional
programming languages that target JavaScript. It's worth comparing both the
GHCJS and Fay implementation approach with ClojureScript which has _no
runtime_ and ships with a full suite of efficient persistent data structures
out of the box. It is also capable today of generating very fast code with
little overhead over hand written JS
[http://swannodette.github.io/2013/06/10/porting-notchs-
minec...](http://swannodette.github.io/2013/06/10/porting-notchs-minecraft-
demo-to-clojurescript/) (and is in fact why the persistent data structures we
ship work so well).

For the folks who swear by static typing, I expect core.typed will eventually
provide that:
[http://github.com/clojure/core.typed](http://github.com/clojure/core.typed)

~~~
Fishkins
I love clojure/clojurescript, but will core.typed really be comparable to
Haskell's type system?

~~~
swannodette
Haskell's type system is crafted for Haskell and core.typed is crafted for
Clojure. I don't see how they can be compared given how different the two
languages are.

~~~
tome
I'd say it the other way round: that Haskell was crafted for Haskell's type
system, i.e. Hindley-Milner.

(Although Haskell also has type-classes which make my statement not quite
true)

~~~
swannodette
I'd say your statement is not true, type classes arrived early on and
adjustments needed to made. I imagine adjustments will continue to be made as
Haskell evolves as a language.

It is true that Haskell & its type system evolve together whereas core.typed
must follow Clojure wherever it may go.

~~~
tome
Mmm, and Haskell added higher-kinded types which are not part of Hindley-
Milner, so yes my initial statement was too simplistic.

------
sfvisser
Note that they have almost the entire runtime working, including the threading
model, which allows you to fork threads, use MVars, perform STM, etc.

Truly awesome and very promising.

~~~
wslh
Is incredible that we don't have an Android or iOS Haskell interpreter but we
can run it on an embedded browser first.

~~~
efnx
I hear ARM support will be standard in the next GHC, and there currently are
ports and cross-compilers. Unless you're specifically talking about ghci,
which I agree needs to be ported, though that hasn't happened for the browser
yet. It's possible a project like this could help that happen, though...

[http://hackage.haskell.org/trac/ghc/wiki/Building/CrossCompi...](http://hackage.haskell.org/trac/ghc/wiki/Building/CrossCompiling)
[https://github.com/ghc-ios/ghc](https://github.com/ghc-ios/ghc)

~~~
wslh
I am looking to the gchi because it's mainly to play and learn . I think a
mobile/tablet is a nice environment to do that.

------
tome
I really hope never to have to write Javascript again.

------
ocharles
There is another option to GHCJS and Fay now - Sunroof
([http://www.ittc.ku.edu/csdl/fpg/software/sunroof.html](http://www.ittc.ku.edu/csdl/fpg/software/sunroof.html))
- which is entirely inside Haskell - no compiler needed other than GHC.

------
wslh
Excellent, but where is the "try now" link to test in the browser?

~~~
luite
I want that too! Dan Frumin is working on a GSoC project that uses GHC, GHCJS
and diagrams to make a "try now" pastebin site with graphics.

Unfortunately, GHCJS is not quite Safe Haskell code, so we are still working
on sandboxing the compiler with SELinux.

his weblog, more updates will follow:
[http://parenz.wordpress.com/](http://parenz.wordpress.com/)

------
pekk
Where are all the people saying that we should only ever use Javascript in the
browser? Mysteriously missing now that the language discussed is Haskell?

~~~
recursive
We should only ever use javascript in the browser.

~~~
efnx
And maybe not even there =P

