by chimeracoder · 12y ago · 0 comments
If you don't have a particular goal in mind (ie, "I work at Jane Street and need to be compatible with our existing code"), there are a number of other factors in the OCaml vs. Haskell discussion that are far more important.
> JS is the only realistic way to write web apps
Javascript is the only realistic way to write the front-end of webapps. But that doesn't mean you're wedded to it for your backend technology. And I don't think either OCaml or Haskell have sufficiently advanced DOM bindings, etc. that I'd recommend using either one for client-side work in the browser.
[0] I'm not sure if this is a flamewar topic for car nerds - my point is to pick two high-end luxury cars that are both well-respected and each have their own merits.
Having a solid implementation for your target platform is very good reason to pick a language.
> Having a solid implementation for your target platform is very good reason to pick a language.
I'm not sure where you got that out of my comment; it was exactly the opposite.
My point was that neither OCaml nor Haskell have particularly strong implementations in this area (to my knowledge). Last time I checked, the ability to write Javascript using both languages was of experimental and/or novelty use only (hence the "cupholders").
And that still doesn't change the fact that a web app can be written in any language - the only part that needs to run in Javascript is the client-side. Depending on how you architect your app, this may not be much at all. (There are very few webapps that actually need much logic in Javascript - if you want to avoid JS[0] while writing complex webapps, it's actually very easy to do so in many cases.)
[0] or anything else that is translated into JS
Facebook uses an OCaml js_of_ocaml-based frontend for a large chunk of their production code editing. Not a great video, but here's the CUFP 2013 talk on the topic: http://www.youtube.com/watch?v=gKWNjFagR9k
Fay is used in production apps as well.
PureScript is less mature still but pretty nice.
This is what I meant when I said "by virtue of support for existing libraries". js_of_ocaml translates compiled bytecode and can therefore make any pure OCaml library work in JavaScript without recompilation.
I think of a web app as the client side alone, which can be quite a substantial amount of code with something like GMail or Google Maps. Of course on the server side, you can make a mostly-independent choice of language, RPC mechanisms aside. But for the client side, I'd choose a language based on how well it compiles to JavaScript and can use browser API's and JavaScript libraries.
I don't know whether OCaml is ahead of Haskell in this space. I've tinkered with Elm a little bit.
They both do.
I'm also looking at whether TyXML can be used with js_of_ocaml for statically typed goodness: http://ocsigen.org/tyxml/
Fay[1], a subset of Haskell that compiles to JavaScript, seems to be the primary choice. There are DOM and jquery bindings for it and this blog post[2] looks like a great introduction.
There are other options, this [3] article outlines a number of them as a greater overview of both server and client side programming with Haskell. I also found an intriguing article [4] on the Haskell site but it appears to be out of date, referencing libraries that are no longer in development.
[1]https://github.com/faylang/fay/wiki
[2]http://ocharles.org.uk/blog/posts/2013-12-23-24-days-of-hack...
[3]http://www.stephendiehl.com/posts/haskell_web.html
[4]http://www.haskell.org/haskellwiki/Haskell_in_web_browser
main = plainText "Hello, World!"
From the page: "Elm is a functional language that compiles to HTML, CSS, and JavaScript".
So yes, technically this is working with the DOM. But you are not writing code that interacts with a "DOM binding" directly per se.
(To clarify: At the time that I last used Elm, the Signal type was a functor, but was intentionally being kept from being a monad for design reasons. Working around this restriction tought me a lot on why I needed monads.
http://purescript.readthedocs.org/en/latest/intro.html#hello...
Imagine that I'm making a page that converts meters to millimeters. The obvious part of the haskell code is
convert :: Double -> Double convert = 1000 *
The part which isn't obvious to me is how I get input from the user or display the result. I know how to do that in the IO monad through standard haskell, but I wouldn't know how to handle it in Haskell compile to javascript for the web browser. I would have thought that you would need a binding to the DOM to read from forms and the like.
$('#toggleLink').click(function() {
if ($('#toggleLink').html() == 'Show') {
showRollout();
$('#toggleLink').html('Hide');
} else {
hideRollout();
$('#toggleLink').html('Show');
]
});