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.

9
  • Why? [maybe there is a reason why they are not maintained!] Commented Jun 7, 2011 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 GOTOs anyway ...) Commented Jun 8, 2011 at 0:21
  • 2
    @Ira: By that argument there should be more car factories in the world than cars. Commented Jun 8, 2011 at 6:51
  • 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. Commented Jun 8, 2011 at 14:13
  • 3
    I want haskell syntax, haskell type enforcement and all this awesome stuff but i need to release javascript code. Commented Jun 11, 2013 at 21:56

6 Answers 6

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

Sign up to request clarification or add additional context in comments.

2 Comments

Elm is another interesting project in this space elm-lang.org
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.
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.

2 Comments

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.
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 (utrechthaskellcompiler.wordpress.com). YHC is dead (yhc06.blogspot.com/2011/04/yhc-is-dead.html), so I wouldn't even consider to evaluate it. jshaskell is a project on Google Code (github.com/balazs-endresz/jshaskell). 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.
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.

4 Comments

@sclv, do you get to try ghcjs? Is it already usable, or for now more of a prototype?
@avernet, I didn't go further than reading the readme-file, so I can't tell.
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).
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.

2 Comments

do you know why it isn't more famous? it's hell of an idea. maybe performance?
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.
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.

Comments

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)

2 Comments

I'm pretty sure Yesod is server side, not client side like JS.
Still Yesod maintainers know about an option to compile Haskell to Javascript and created their own rating for the tools.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.