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.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
avernet
  • 30,895
  • 44
  • 126
  • 163
  • Why? [maybe there is a reason why they are not maintained!] – epascarello Jun 07 '11 at 22:22
  • 4
    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 `GOTO`s anyway ...) – Jörg W Mittag Jun 08 '11 at 00:21
  • @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? – Ira Baxter Jun 08 '11 at 01:53
  • 2
    @Ira: By that argument there should be more car factories in the world than cars. – hammar Jun 08 '11 at 06:51
  • @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? – Ira Baxter Jun 08 '11 at 13:59
  • 5
    @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. – hammar Jun 08 '11 at 14:13
  • 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. http://goo.gl/F8xbu – avernet Jun 15 '11 at 01:23
  • 3
    I want haskell syntax, haskell type enforcement and all this awesome stuff but i need to release javascript code. – lud Jun 11 '13 at 21:56
  • @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. – Alice Mar 02 '15 at 01:29

6 Answers6

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

Pandafox
  • 564
  • 1
  • 5
  • 18
David
  • 8,340
  • 7
  • 49
  • 71
  • 2
    Elm is another interesting project in this space http://elm-lang.org/ – Ben Racine Jan 30 '13 at 17:57
  • 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. – Will Sewell May 07 '14 at 20:32
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.

jerng
  • 499
  • 6
  • 13
  • do you know why it isn't more famous? it's hell of an idea. maybe performance? – András Gyömrey Dec 19 '12 at 21:57
  • 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. – jerng Dec 25 '12 at 17:12
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.

Adam Gent
  • 47,843
  • 23
  • 153
  • 203
  • 3
    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](http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/Backends/LLVM). – ZyX Jun 08 '11 at 11:18
  • 2
    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 (http://goo.gl/cX4fN). YHC is dead (http://goo.gl/icNTo), so I wouldn't even consider to evaluate it. jshaskell is a project on Google Code (http://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. – avernet Jun 09 '11 at 00:33
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.

Rotsor
  • 13,655
  • 6
  • 43
  • 57
  • 2
    on ghcjs, see also: http://www.haskell.org/pipermail/haskell-cafe/2011-May/091897.html – sclv Jun 15 '11 at 20:20
  • @sclv, do you get to try ghcjs? Is it already usable, or for now more of a prototype? – avernet Jun 15 '11 at 22:58
  • @avernet, I didn't go further than reading the readme-file, so I can't tell. – Rotsor Jun 16 '11 at 00:43
  • 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). – Erik Kaplun Apr 21 '15 at 09:43
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.

KajMagnus
  • 11,308
  • 15
  • 79
  • 127
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)

Gerold Meisinger
  • 4,500
  • 5
  • 26
  • 33
  • I'm pretty sure Yesod is server side, not client side like JS. – jmite Aug 30 '13 at 02:38
  • 1
    Still Yesod maintainers know about an option to compile Haskell to Javascript and created their own rating for the tools. – Anton Oct 15 '14 at 18:08