[Haskell-cafe] Tutorial on JS with Haskell: Fay or GHCJS?

Adam Bergmark adam at edea.se
Wed Sep 4 15:39:42 CEST 2013


Here are some points I'd like to emphasize in addition to the threads
above, with the disclaimer that I'm the maintainer of Fay.

Fay tries to be very simple, the code base is small (~4800 LoC). This
really lowers the entry barrier for contributions which I think is very
important for open source projects. GHCJS is much more complicated since it
tries to do so much. For GHCJS I'd be afraid that the developers might
eventually abandon the project and then it'd be pretty hard to take over
development. Much easier for someone to take over Fay development. I think
you can safely expect to find bugs in all compilers, and if you do and you
are in a hurry you might have to fix it yourself. Fay has very simple
output that is close to both Haskell and JavaScript so it's pretty easy to
just add a breakpoint and start debugging.

Even if GHCJS can successfully compile most of hackage, would we want to
have these as dependencies in web projects? An output size of 1MiB is
nothing when compiling a binary, but for a public website 1MiB can still be
quite a lot, add some transitive dependencies and output will explode. Most
people don't optimize their packages to have few dependencies, which makes
sense since the abstraction usually heavily outweighs code size. So either
way you would probably want to write some specific light-weight versions of
libraries you want to use, that's one reason both GHCJS and Fay have their
own base packages.

One place I think GHCJS can shine is for non standard web applications such
as WEBGL games. Nothing stopping you from using Fay for this, but I expect
you can really start to leverage GHCJS's threaded runtime here.

I'm not sure if GHCJS or Haste have any out of the box solutions for doing
client<->server communication. In Fay you can just serialize any data type
automatically on the front and backend to a json format and then
deserialize it automatically again on the other end. You can also leverage
phantom types (
https://github.com/fpco/yesod-fay/blob/master/Language/Fay/Yesod.hs#L41) to
typecheck this communication.

It's hard to know how well GHCJS performs in a real web application. FP
Complete uses Fay for their IDE and School of Haskell so it has been battle
tested, so if you want something that definitely works today I think Fay is
the more reliable option.

It is possible that GHCJS will eventually supercede Fay. But if you want
something that's easy to use today you can always write Fay, and then
convert it to GHCJS later since Fay is a subset of Haskell.

I think GHCJS needs more time to prove itself. I know the developers are
hard at work and I hope they will focus on a lot of learning materials.
Once you can `cabal install ghcjs` and just get started I think they will
see a lot more interest coming their way.

Let me know if you have more questions. If you decide to use Fay in your
tutorial I'd be happy to help out, just send me an e-mail!

- Adam



On Wed, Sep 4, 2013 at 2:46 PM, Adam Bergmark <adam at edea.se> wrote:

> You might be interested in these two comment threads (and maybe the rest
> of the comments as well):
>
> http://www.reddit.com/r/haskell/comments/1ldqav/thoughts_on_uhc_vs_haste_vs_fay/cbyrhwz
>
> http://www.reddit.com/r/haskell/comments/1htqi2/announce_haste_the_haskell_to_js_compiler_is_now/cay79g9?context=1
>
>
>
> On Wed, Sep 4, 2013 at 12:36 PM, Nathan Hüsken <nathan.huesken at posteo.de>wrote:
>
>>  In my opinion haste is somewhere between Fay and ghcjs. It supports
>> more than Fay, but in difference to ghcjs some PrimOps are not supported
>> (weak pointers for example).
>>
>> It is a little bit more "direct" than ghcjs, in the sense that it does
>> not need such a big rts written in js.
>>
>> I like haste :).
>>
>> What I wonder is how the outputs of these 3 compilers compare speed wise.
>>
>>
>> On 09/04/2013 11:11 AM, Alejandro Serrano Mena wrote:
>>
>> I haven't looked at Haste too much, I'll give it a try.
>>
>>  My main problem is that I would like to find a solution that will
>> continue working in years (somehow, that will became "the" solution for
>> generating JS from Haskell code). That's why I see GHCJS (which just
>> includes some patches to mainstream GHC) as the preferred solution, because
>> it seems the most probable to continue working when new versions of GHC
>> appear.
>>
>>
>> 2013/9/4 Niklas Hambüchen <mail at nh2.me>
>>
>>> Hi, I'm also interested in that.
>>>
>>> Have you already evaluated haste?
>>>
>>> It does not seem to have any of your cons, but maybe others.
>>>
>>> What I particularly miss from all solutions is the ability to simply
>>> call parts written in Haskell from Javascript, e.g. to write `fib` and
>>> then integrate it into an existing Javascript application (they are all
>>> more interested in doing the other direction).
>>>
>>> On Wed 04 Sep 2013 17:14:55 JST, Alejandro Serrano Mena wrote:
>>> > Hi,
>>> > I'm currently writing a tutorial on web applications using Haskell. I
>>> > know the pros and cons of each server-side library (Yesod, Snap,
>>> > Scotty, Warp, Happstack), but I'm looking for the right choice for
>>> > client-side programming that converts Haskell to JavaScript. I've
>>> > finally come to Fay vs. GHCJS, and would like your opinion on what's
>>> > the best to tackle. My current list of pros and cons is:
>>> >
>>> > Fay
>>> > ===
>>> > Pros:
>>> > - Does not need GHC 7.8
>>> > - Easy FFI with JS
>>> > - Has libraries for integration with Yesod and Snap
>>> >
>>> > Cons:
>>> > - Only supports a subset of GHC (in particular, no type classes)
>>> >
>>> >
>>> > GHCJS
>>> > ======
>>> > Pros:
>>> > - Supports full GHC
>>> > - Easy FFI with JS
>>> > - Highly opinionated point: will stay longer than Fay (but it's very
>>> > important for not having a tutorial that is old in few months)
>>> >
>>> > Cons:
>>> > - Needs GHC 7.8 (but provides a Vagrant image)
>>> >
>>> >
>>>  > _______________________________________________
>>> > Haskell-Cafe mailing list
>>> > Haskell-Cafe at haskell.org
>>> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing listHaskell-Cafe at haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130904/c21786a5/attachment.htm>


More information about the Haskell-Cafe mailing list