What is the most production-level Haskell to JavaScript compiler, to write code running in the browser? [closed]
Asked Answered
A

6

58

I am not looking for a necessarily super-robust solution with a 10-year track record, but for something that can be used in a real applications, and goes beyond just being able to run an Hello World example.

My preference is to run the compiler on the server, so I can compile Haskell code ahead of time. Of course, the solution would need to be more than just a compiler, and enable Haskell code to access the API available on the browser (DOM, XHR…).

Footnote: the projects I have seen so far don't seem to be actively maintained, or to go beyond being able to run "Hello world", or in some case even to go beyond a project description.

Agnostic answered 7/6, 2011 at 22:13 Comment(9)
Why? [maybe there is a reason why they are not maintained!]Coarsen
Most existing Haskell implementations compile to C or x86. I'm pretty sure there's more deployed ECMAScript engines than either C or x86 engines. So, it makes perfect sense, doesn't it? ECMAScript is a pretty fine assembly language, too, except it desperately needs GOTO, continuations, a reified stack or something like that. (Note: I'm only talking of ECMAScript as an assembly language. Adding GOTO to ECMAScript as a programming language would be a terrible mistake. Continuations OTOH would be pretty cool. Well, actually ECMASCript already has exceptions which are GOTOs anyway ...)Infelicitous
@Jorg: uh, aren't most JavaScript engines implemented in C? Implications: #(JavaScriptEngines)<=#(CEngines). And the number of x86 engines on the planet is pretty astonishing. Why target JavaScript with so many C and x86 engines lying around?Assyrian
@Ira: By that argument there should be more car factories in the world than cars.Disjunctive
@hammar: while your argument is "cute", x86s are in pretty wide actual distribution (likely more of them than actual cars). C compilers may not actually have such wide distribution in practice, but given for any JavaScript implementation there was likely a C compiler [with a significant fraction of these likley being GCC], and such compilers in general are not hard to get, anybody contemplating a JavaScript target can surely acquire the corresponding C compiler without a lot of effort. So I just don't see the point. What does a Haskell programmer get out a JavaScript implementation?Assyrian
@Ira: It is almost certainly true that there are more C implementations than JavaScript ones, although this does not follow logically from the fact that most of them are written in C. Anyway, I guess compiling Haskell to JavaScript is mostly motivated by a desire to have access to the strong static guarantees of Haskell in the browser.Disjunctive
After reading the first two comments, and having asked the question myself, I have to post a link to Steve Yegge's blog post "Haskell Researchers Announce Discovery of Industry Programmer Who Gives a Shit". Enjoy. goo.gl/F8xbuAgnostic
I want haskell syntax, haskell type enforcement and all this awesome stuff but i need to release javascript code.Izaak
@JörgWMittag What in the world are you talking about? There are far more x86 chips out there than EMCAscripting engines, and there are tons more C compilers than JS VIMs. A cursory google search would have verified this. Furthermore, exceptions are NOT goto's; they are far more powerful in general.Come
K
21

There is a more complete list here:

http://www.haskell.org/haskellwiki/The_JavaScript_Problem

and there is also Fay (although it is only a subset of haskell)

https://github.com/faylang/fay

Kiyokokiyoshi answered 14/5, 2012 at 12:51 Comment(2)
Elm is another interesting project in this space elm-lang.orgKaneshakang
And judging by the linked wiki page. JMacro seems like its most mature, but is just a EDSL within Haskell. Haste seems like the next most mature, and seems more faithful to haskell itself. I looked at its Github page, and it seems to be actively maintained.Patterson
A
9

You may find this List useful: https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS

From the List:

* UHC (Utrecht Haskell Compiler) backend converts UHC core to JavaScript, allowing the compiling of Haskell code to JS.
* YHC (York Haskell Compiler) backend, as above but with YHC core language.
* jshaskell

I know its not Haskell but Coffee script is expression based and rather elegant IMHO.

Apocope answered 7/6, 2011 at 22:31 Comment(2)
In this list «Emscripten LLVM to JavaScript compiler.» is under C/C++ section which is wrong as it can compile any language that can be compiled to LLVM bytecode, including Haskell.Rival
Out of those, UHC looks the most promising. As of today, its last release was in Oct 2010, and they have a blog with JavaScript specific posts (goo.gl/cX4fN). YHC is dead (goo.gl/icNTo), so I wouldn't even consider to evaluate it. jshaskell is a project on Google Code (goo.gl/d85K4). As of today, the repository hasn't been touched since Jul 2010, and Google Code describes the activity of the project as "None"; not very encouraging.Agnostic
C
9

I have stumbled upon this project called ghcjs

It seems promising!

Quote from the README:

Haskell to Javascript translator

Project aims to provide solution to

  • compile modern Haskell libraries to Javascript files and use them in Ajax applications or
  • develop entire Ajax application in Haskell language

Previous version of project is located at vir.mskhug.ru.

Cosmography answered 15/6, 2011 at 19:43 Comment(4)
on ghcjs, see also: haskell.org/pipermail/haskell-cafe/2011-May/091897.htmlHotze
@sclv, do you get to try ghcjs? Is it already usable, or for now more of a prototype?Agnostic
@avernet, I didn't go further than reading the readme-file, so I can't tell.Cosmography
I can say that as of 2015 april, GHCJS seems highly approachable and quite mature; I was able to get to a running Hello World without a glitch, which I cannot say about Haste at this time (which is the only other "true", i.e. non-dialect Haskell->JS compiler).Virg
O
9

While GHCJS does not seem to be actively maintained, Emscripten seems to be quite current.

  • Emscripten compiles LLVM bitcode to JavaScript.
  • GHC's LLVM backend appears to be actively developed.
  • Intuitively, to answer the question, the following pipeline might not be very far from "production quality": Haskell lexemes (-> GHC ->) LLVM lexemes (-> Emscripten ->) JavaScript lexemes

I'll admit that this is a speculative post.

Oxysalt answered 5/12, 2012 at 18:49 Comment(2)
do you know why it isn't more famous? it's hell of an idea. maybe performance?Friday
One guy seems to have got it working before. (Google for it.) Could not find any other information on that in the past. Maybe it's not in demand. I haven't had time to test it. Maybe soon.Oxysalt
R
2

This language, Roy, is perhaps not really Haskell (?), but it seems very similar:

http://roy.brianmckenna.org/

Roy seems to be alive; there are many forks in the GitHub repo: https://github.com/pufuwozu/roy
and it seems to be alive: https://github.com/pufuwozu/roy/graphs


If you're using Play Framework 2.0, then there's a plugin, Ray, to run Roy on Play Framework 2.0:

http://brianmckenna.org/blog/ray
https://github.com/pufuwozu/ray

The last commit was four months ago, which is rather long ago keeping in mind that Play Framework 2 was released perhaps 4 or 5 months ago.

Radiothermy answered 19/6, 2012 at 2:16 Comment(0)
C
0

There is a list of "most production level" candidates from Yesod: https://github.com/yesodweb/yesod/wiki/Javascript-Options (Yesod is a very popular Haskell webframework so they may know what they are talking about)

Calpe answered 23/5, 2012 at 19:58 Comment(2)
I'm pretty sure Yesod is server side, not client side like JS.Sphygmomanometer
Still Yesod maintainers know about an option to compile Haskell to Javascript and created their own rating for the tools.Cotopaxi

© 2022 - 2024 — McMap. All rights reserved.