Haskell/JS -- better through typeclasses?

I'd like to be able to translate Haskell to JavaScript. Many Haskell/JS bridges provide libraries for writing complete JavaScript programs in Haskell; some of them even include jQuery. However, my goals are more limited -- I'd like to be able to take a Haskell module and turn it into a JavaScript object. For example, I'd like to write a nice parser in Haskell and then reuse it on the client side. No need to handle all the DOM events or implement multi-threading. Of course, the place to start is by reading the commentary. A little bit of browsing suggests some questions of strategy: . Maybe a new backend is not the right thing? All the backends seem to be for real computers with real instruction sets. . Is it better to just work on transforming Core into JS directly? It seems that "External Core" is still in limbo. . Some translations strike me as baffling in principle. For example, a value like `ones`: ones = 1 : ones We'd want to avoid most native JavaScript containers, it seems; however, we are then unable to leverage the speed of native containers. It's entirely possible that translating Haskell to JavaScript may turn out not to be the best idea; maybe it is better to have a type class for types (for example, `Parser Char`) to provide their own translators? The it would be straightforward to prevent translation of programs that use concurrency libs, native ops or `IO`. -- Jason Dusek

On 25 Apr 2009, at 21:53, Jason Dusek wrote:
Many Haskell/JS bridges provide libraries for writing complete JavaScript programs in Haskell; some of them even include jQuery. However, my goals are more limited -- I'd like to be able to take a Haskell module and turn it into a JavaScript object.
Many books explain how to grow a baby hippo; some of them even include instructions for treating it when it's sick. However, my goals are more limited -- I'd like to be able to take an elephant and turn it into a grown-up hippo.

I tried using the jhc javascript compiler back end a year or so ago.
It was too rough to use in production, but it did output javascript
from haskell.
thomas.
2009/4/25 Miguel Mitrofanov
On 25 Apr 2009, at 21:53, Jason Dusek wrote:
Many Haskell/JS bridges provide libraries for writing complete JavaScript programs in Haskell; some of them even include jQuery. However, my goals are more limited -- I'd like to be able to take a Haskell module and turn it into a JavaScript object.
Many books explain how to grow a baby hippo; some of them even include instructions for treating it when it's sick. However, my goals are more limited -- I'd like to be able to take an elephant and turn it into a grown-up hippo.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On second thought, it was yhc, not jhc:
http://lambda-the-ultimate.org/node/1836
2009/4/25 Thomas Hartman
I tried using the jhc javascript compiler back end a year or so ago.
It was too rough to use in production, but it did output javascript from haskell.
thomas.
2009/4/25 Miguel Mitrofanov
: On 25 Apr 2009, at 21:53, Jason Dusek wrote:
Many Haskell/JS bridges provide libraries for writing complete JavaScript programs in Haskell; some of them even include jQuery. However, my goals are more limited -- I'd like to be able to take a Haskell module and turn it into a JavaScript object.
Many books explain how to grow a baby hippo; some of them even include instructions for treating it when it's sick. However, my goals are more limited -- I'd like to be able to take an elephant and turn it into a grown-up hippo.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

2009/04/25 Thomas Hartman
2009/04/25 Thomas Hartman
: I tried using the jhc javascript compiler back end a year or so ago. On second thought, it was yhc, not jhc:
Yeah, I think that thing has been dead for awhile. Also it does a lot more than I want -- I don't want to write my UI logic in Haskell at present. The AJAX toolkits are pretty good and it would be a waste to try to translate them into Haskell and keep them updated. I would like to be able to write a lot of supporting code in Haskell, though -- like parsers. Actually, parsers are really all I care about at present. -- Jason Dusek

2009/04/25 Miguel Mitrofanov
2009/04/25 Jason Dusek wrote:
Many Haskell/JS bridges provide libraries for writing complete JavaScript programs in Haskell; some of them even include jQuery. However, my goals are more limited -- I'd like to be able to take a Haskell module and turn it into a JavaScript object.
Many books explain how to grow a baby hippo; some of them even include instructions for treating it when it's sick. However, my goals are more limited -- I'd like to be able to take an elephant and turn it into a grown-up hippo.
Many persons use images in the form of analogy or metaphor to communicate a message. However, my goals are more limited -- I'd like to use images without analogy or metaphor. -- Jason Dusek

On Apr 25, 2009, at 13:53 , Jason Dusek wrote:
I'd like to be able to translate Haskell to JavaScript.
http://haskell.org/haskellwiki/Yhc/Javascript ?
Many Haskell/JS bridges provide libraries for writing complete JavaScript programs in Haskell; some of them even include jQuery. However, my goals are more limited -- I'd like to be able to take a Haskell module and turn it into a JavaScript object. For example, I'd like to write a nice parser in
That's not exactly limited; building a self-contained program is easier than producing something that seamlessly adapts between different runtimes with very different notions of how the world works. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

2009/04/25 Brandon S. Allbery KF8NH
2009/04/25 Jason Dusek:
I'd like to be able to translate Haskell to JavaScript.
Dead.
Many Haskell/JS bridges provide libraries for writing complete JavaScript programs in Haskell; some of them even include jQuery. However, my goals are more limited -- I'd like to be able to take a Haskell module and turn it into a JavaScript object. For example, I'd like to write a nice parser in
That's not exactly limited; building a self-contained program is easier than producing something that seamlessly adapts between different runtimes with very different notions of how the world works.
What I mean is a bucket of JavaScript functions. It would be fine to hide all the data constructors and type definitions. -- Jason Dusek

I'd like this functionality, as well, but it doesn't exist, at least for Haskell. If you don't need a 100% pure functional language, and don't need the bells and whistles of the Haskell type system, you might be interested in SML -- a purer relative of the more widely-known Ocaml. There's a tool for converting SML to JavaScript: http://www.itu.dk/people/mael/smltojs/ It allows you to export SML functions so they can be called by JavaScript. Moreover, it has a reactive library built in, does pretty decent optimization, lets you manipulate the DOM, and is up to version 4.3.5. Haskell doesn't have anything close! Regards, John A. De Goes N-BRAIN, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Apr 25, 2009, at 11:53 AM, Jason Dusek wrote:
I'd like to be able to translate Haskell to JavaScript.
Many Haskell/JS bridges provide libraries for writing complete JavaScript programs in Haskell; some of them even include jQuery. However, my goals are more limited -- I'd like to be able to take a Haskell module and turn it into a JavaScript object. For example, I'd like to write a nice parser in Haskell and then reuse it on the client side. No need to handle all the DOM events or implement multi-threading.
Of course, the place to start is by reading the commentary. A little bit of browsing suggests some questions of strategy:
. Maybe a new backend is not the right thing? All the backends seem to be for real computers with real instruction sets.
. Is it better to just work on transforming Core into JS directly? It seems that "External Core" is still in limbo.
. Some translations strike me as baffling in principle. For example, a value like `ones`:
ones = 1 : ones
We'd want to avoid most native JavaScript containers, it seems; however, we are then unable to leverage the speed of native containers.
It's entirely possible that translating Haskell to JavaScript may turn out not to be the best idea; maybe it is better to have a type class for types (for example, `Parser Char`) to provide their own translators? The it would be straightforward to prevent translation of programs that use concurrency libs, native ops or `IO`.
-- Jason Dusek _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

For parsers, there is also a LALR(1) generator - http://jscc.jmksf.com/ - though I have not had personal experience with it. --A
participants (7)
-
Anton Tayanovskyy
-
Brandon S. Allbery KF8NH
-
Jason Dusek
-
John A. De Goes
-
Miguel Mitrofanov
-
Stefan Monnier
-
Thomas Hartman