Live data from Hacker News

Melange 1.0: Compile OCaml / ReasonML to JavaScript

buttondown.email

41–50 of 55 posts

Re: Melange 1.0: Compile OCaml / ReasonML to JavaScript

#41
post #10

I have nothing to say other than thank you! I might not use OCaml often myself, but I appreciate the effort to improve the ML ecosystem in any way :) I was a bit disappointed with the ReScript fork abandoning the compatibility with OCaml so this project was welcome news

I have only worked with ReScript for about a year before switching to ClojureScript (which was a better fit for my project), but I really enjoyed the experience and genuinely wish it would become a more popular alternative to TypeScript for devs who are coming from JS and are looking to dive into FP and static typing. The developer team did a great job with highly optimized and readable JS compilation, great integration and interop with React, JSX support, raw JS and even TypeScript (see GenType) and now it also supports async/await. The website is also really well made and provides good documentation and a nice forum to get help when needed.

However, Melange seems to head in a good direction too and I guess it would be amazing for people who are already familiar with OCaml and want to integrate with libraries and codebases there. So I think both projects are valuable in their own right for different use-cases.

Re: Melange 1.0: Compile OCaml / ReasonML to JavaScript

#42
post #33
post #27

Earlier quoted context omitted.

Out of curiosity, what do you think the issues with js_of_ocaml were?

The main problems as I perceive it: - unreadable generated code (aka, hard to debug in the browser) - not very accessible (complex docs, unclear what it is or how to use it)

on any decent size application the output of bucklescript/rescript/melange is also unreadable. I never understood that argument.

some real problems with jsoo are (non exhaustive list)

- "heavy" FFI (both in term of setup and syntax)

- the output is a big single .js file, which doesn't allow reloading of a single component and doesn't integrate well with stuff like webpack

- slower compilation time

- lacking documentation for the javascript audience

Re: Melange 1.0: Compile OCaml / ReasonML to JavaScript

#43
post #34

As if the whole Reason/ReScript story wasn't complicated enough already :D First, we had BuckleScript, that compiled OCaml to JavaScript to bring the OCaml type system to the Web. Then we had Reason, that brought JS syntax to OCaml, so it's easier to grasp for JS devs. Seemingly, some people didn't care about OCaml at all, and forked (I guess?) Reason to ReScript, that focused on JS compilation. They also added a few…

Wasn't there also another OCaml-to-Javascript compiler called called js_of_ocaml?

Re: Melange 1.0: Compile OCaml / ReasonML to JavaScript

#44

Just a note, melange is also the name of a computer language workbench from INRIA ( http://melange.inria.fr/ ) and an APK builder ( https://edu.chainguard.dev/open-source/melange/overview/ ) Both of those came up before melange.re when searching for a hello world example.

Melange is the name of the desert spice that grants prescience in the Dune series, so this isn't too much of a coincidence.

Re: Melange 1.0: Compile OCaml / ReasonML to JavaScript

#45

Can someone please expain the state of doing async with Melange? ReasonML never had an answer in that important area to my knowledge.

You can treat async stuff just like you would treat any other effect like Option or Result. And then let bindings (because Melange supports newer Ocaml) give you similar imperative looking code but not specific to async.

Re: Melange 1.0: Compile OCaml / ReasonML to JavaScript

#46
post #25

Might as well ask this here, but any thoughts on how ReScript / ReasonML compare to Elm, PureScript, or ClojureScript? If someone were looking for a fp language that compiled to JS, how would they think about the pros and cons of the available options? Last discussion I could find was from 2018 [1]. [1] https://news.ycombinator.com/item?id=17910069

Clojurescript has a lot of interesting stuff behind it, but honestly Clojure stuff has a pretty high learning curve (CLI tools whose error messages are extremely unhelpful, docs that are pretty minimal, and other things that make falling off the happy path rough). I think it's a very interesting "serious" choice, especially if you also want to run stuff as Clojure. But I found it a bit hard to get into.

Purescript has, I think, some of the most interesting things going for it from a FP language, as its effects system paired with the very nice support for JS objects through Record means you can build effects systems like "this function reads from the DB" vs "this function writes to the DB", or "this function accesses a single user's data" vs "this function is multitenant". The FFI story is also very straightforward IMO.

ReScript feels close to Elm in that it's very focused on a straightforward usage of ML and isn't trying to be fancy. I haven't messed with it in a while but honestly OCaml is pretty straightforward and lets you easily fallback to simple imperative tricks in a way that Clojurescript and Purescript don't.

I think if you want to go full FP, Purescript has the most interesting stuff to bring to the table (and because it's not lazily evaluated the mental model is not hard). ReScript has the easiest onboarding IMO... and Clojurescript is good if you're into Clojure/lisp-y stuff in general. But they're all very distinct flavors and it's ultimately a bit of an aesthetic choice IMO

Re: Melange 1.0: Compile OCaml / ReasonML to JavaScript

#47
post #34

As if the whole Reason/ReScript story wasn't complicated enough already :D First, we had BuckleScript, that compiled OCaml to JavaScript to bring the OCaml type system to the Web. Then we had Reason, that brought JS syntax to OCaml, so it's easier to grasp for JS devs. Seemingly, some people didn't care about OCaml at all, and forked (I guess?) Reason to ReScript, that focused on JS compilation. They also added a few…

The biggest issue with Reason and Elm is that they don't support integration with arbitrary npm packages. That's the fastest way to gain adoption. If you are going to launch a new frontend language and you are not google, the quickest method is to have out of the box compiler support for the existing JS ecosystem.

Re: Melange 1.0: Compile OCaml / ReasonML to JavaScript

#49
post #34

As if the whole Reason/ReScript story wasn't complicated enough already :D First, we had BuckleScript, that compiled OCaml to JavaScript to bring the OCaml type system to the Web. Then we had Reason, that brought JS syntax to OCaml, so it's easier to grasp for JS devs. Seemingly, some people didn't care about OCaml at all, and forked (I guess?) Reason to ReScript, that focused on JS compilation. They also added a few…

The biggest issue with Reason and Elm is that they don't support integration with arbitrary npm packages. That's the fastest way to gain adoption. If you are going to launch a new frontend language and you are not google, the quickest method is to have out of the box compiler support for the existing JS ecosystem.

Both Melange and Rescript support using any arbitrary npm package or librrary

Re: Melange 1.0: Compile OCaml / ReasonML to JavaScript

#50
post #25

Might as well ask this here, but any thoughts on how ReScript / ReasonML compare to Elm, PureScript, or ClojureScript? If someone were looking for a fp language that compiled to JS, how would they think about the pros and cons of the available options? Last discussion I could find was from 2018 [1]. [1] https://news.ycombinator.com/item?id=17910069

I have looked at or tried all of them, except Reason, about 1 year ago. Purescript has (had?) the best tutorial: Purescript by Example. I guess it's also suitable for somebody, who doesn't know Haskell's way of doing things: https://book.purescript.org/chapter1.html https://github.com/purescript-contrib/purescript-book

In order of time programming in each language:

Elm: no, because of the JS interop (didn't even try it).

Clojurescript: really slow REPL, uses Google's closure compiler which had it's own problems (I don't remember what these were, but something with modules). Both Emacs and VS Code (Cider/Calva) did have to many small errors and inconveniences using CS. All in all it had been an unpleasant experience.

ReScript: The language itself is OK-ish (I would have preferred OCaml syntax), the compiler is fast as OCaml. The generated JS is really readable. One year ago there had been no async and the documentation had been missing stuff like functors (I've "found" them at the Rescript forum). But in the end it didn't have enough advantages over TS to cancel out TS' _way_ better developer tools/integration or even Purescript, but this may have changed in the last year (async has been added and functors are now documented, as I've just seen). On the other hand, I would nowadays use Melange instead, I don't see any reason[what a pun!] to use Rescript any more.

PureScript: It is a better (strict) Haskell (with less features). I've used (non-hook) Halogen, I don't know about the React bindings. I had never made an web app (progressive or not) before, so I had to learn everything starting at 0. This has been the result, which has been a quite smooth experience: https://github.com/Release-Candidate/Notoy-PWA#purescript

Post reply on HN