When we (darklang.com) were working with Rescript, I was not optimistic about Melange's approach, but in retrospect I think it has legs.
The challenge with ReScript is that the authors really were focusing on the JS ecosystem, and didn't care at all about OCaml. Their fusion with the ReasonML community didn't make a whole lot of sense. ReScript is a much better language now that it has split than it was then, if you look solely through the lens of a better JS.
But, as Elm and other compiled-to-JS languages have learned, Typescript has gotten good enough that other languages might not be sufficiently better than TS to attract enough interest to have a vibrant community. Doubly so since the JS-interop story isn't nearly as good in ReScript as it is in Typescript (though it's much much better than in Elm).
However, the aim of writing programs in OCaml which compile to nice JS and also native OCaml, and allowing both client and server to be written in OCaml, remains valid and interesting (and I would argue was held back by js_of_ocaml, the pre-existing way to do it). So I think there is something interesting here, though it isn't a ReScript competitor except tangentially.
Though I cannot really understand where ReasonML (a JS-like syntax for OCaml) fits into this - if the target is OCaml devs, than surely the ReasonML syntax stuff is not valuable anymore?
Your perspective on the project is exactly how we think about it: Melange provides the tooling for fullstack (@davesnx likes to call them Universal) Reason/OCaml applications.
I suspect my time in Clojure(Script) has heavily influenced how I look at a "Language of the System"[1], and that's effectively what we're trying to do here.
Re: ReasonML, I very much understand the sentiment. In my mind right now, ReasonML is only there to provide JSX and reason-react support. I suspect we'll eventually write a JSX PPX for OCaml and stop using ReasonML down the road (fairly longer term).
Thanks for Melange! I fully believe in the mission, backing, and philosophy of Melange over ReScript.
To add a counterpoint, though I'm in the minority, I think ReasonML is really really important to keep OCaml accessible to a larger amount of people. I work in a very cross-platform context and program in 5/6 different languages a month, and despite having a lot of experience with different syntaxes, OCaml is just weirdly unique enough that it's hard to immediately transfer my skills. I haven't written OCaml seriously in a while, and even looking back on my own code, for example the PPX I wrote https://github.com/AriaFallah/ppx_str 5 years ago, I can't really read it without zoning in and thinking quite hard vs. just flowing.
You also make a good point. I didn't go into too much detail about ReasonML in another comment, but I know Jordan (@jordwalke) has plans for a ReasonML v4 [1] with slight syntax improvements. I don't currently know the status of that work, however, but I think we'll want to make progress soon.
So the TL;DR is more that ReasonML is not going anywhere, especially since Ahrefs have a huge ReasonML frontend codebase [2].
I think it has value in that some people find OCaml syntax confusing, especially developers who have only had experience with C-style languages. For them, ReScript makes sense as an alternative syntax to a great language!
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)
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
Me too. I think the ReScript people were well within their rights to fork off - they realized that what they wanted was a better JS and compatibility with OCaml held them back, but it also split an already small community and made it hard for me to convince even myself to pick OCaml for hobby projects. I'm glad melange is picking up and becoming viable, and once the situation with multicore and web frameworks built on multicore stabilizes I'd love to make a full-stack OCaml web app.
I'm also pleased to see this, as somebody who likes functional programming and ML dialects. I don't need braces just because C has them.
BuckleScript, when it was called that, was incredibly compelling for me. This was in part thanks to being blazing fast, unlike TypeScript. So I am pleased to see a spiritual successor.
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.
Good to hear they're providing a good dev experience. My only gripe at the time was more of a worry on whether the split was going to be worthwhile because the ML ecosystem is already so small, but I'm glad to hear the project has been effective for you.
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 syntax changes in the process.
Now, the remaining (pre-fork) Reason people created a new(?) compiler that's an alternative to BuckleScript, and compiles OCaml and Reason to JS.
While I appreciate the effort, and think ReScript and Reason are superior to TypeScript, I totally understand why it didn't get as popular as this superiority implies.
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.
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?
The biggest differences between Elm and ReScript/ReasonML as language features are bindings, JSX and purity. Bindings in Elm are cumbersome and limited (on purpose) while in ReScript/ReasonML are easy, more feature complete and a little more fragile. JSX is exactly as React, while Elm doesn't have it; some people prefer it, some people don't. I love it.
Purity in general terms makes Elm more strict while ReasonML/ReScript allow impurity when needed, still most APIs enforce functional style, immutability and proper data structures.
Regarding community, there's drama everywhere not sure If I can do a good job here. Maybe community size Elm is much bigger than others, but they need to reinvent most of tooling that is done in JS and ReScript/Reason takes advantage.
I encourage to not rely on anyones opinion about what's better, because you listed 5 languages with opposite directions.
Try it out yourself and decide based on users/team needs. Cheers.
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
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
What is the status of ReasonML? My first experiences with ReasonML were very nice, because I found OCaml syntax confusing. I kinda left around the time ReScript got introduced.
But OCaml syntax after a while isn't that bad, and in F# and Scala land I do miss the compile time speed of OCaml.
ReasonML purely as a syntax layer on top of OCaml is still being updated and released[1]. Incidentally, I'm one of the maintainers of that project too :-)
With this Melange release, we're hoping to somewhat revive ReasonML and channel some folks back to the community from the perspective of a vertically integrated platform[2] that has seen major investment in the past few years.
First multicore, now this? This makes me really happy.
OCaml is the most fun I've ever had writing code; seeing this after the whole Re* rebranding death spiral makes me hopeful that fullstack OCaml is still a possibility.
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.
AFAIU, ReScript is a new language that offers an alternative to TypeScript.
Melange approaches the problem from the perspective of compatibility with OCaml / ReasonML. We've focused very hard on vertical integration with the OCaml Platform[1] and we're getting all the benefits with this release!
That said, both communities are fairly small, and I don't doubt that somewhat competing projects have some impact on community. From our perspective (the Melange team), our goals fit a specific use case, and e.g. Ahrefs, one of the leading SEO engines in the world, is using Melange[2] in production to power all their web experiences.
Thanks for putting the time and effort into this.
I was very sad to see the departure of rescript, so I am happy to see this wonderful toolchain back to the Ocaml ecosystem.
A lot of the ecosystem is written in TypeScript (heavy on structural typing). Last I've checked OCaml still doesn't have substructural row polymorphism or set theoretic types, so this seems to be a futile endeavor until underlying fundamentals in its type system are addressed.
Why would you need substructural typing to emulate Typescript? Is there a substructural type system feature in TS?
You can accomplish width subtyping with OCaml's "polymorphic variants", which could be used to emulate TS union types more flexibly than traditional sum types.
What are the features of Elm and Purescript that help model TS that OCaml doesn't have?
Congratulations on the project @anmonteiro90. Reading the thread makes me understand more about the situation of Rescript and ReasonML after the split. It’s totally makes sense now. I hope to pick up some OCaml project soon
Melange approaches the problem from the OCaml perspective. It inserts itself within the OCaml community, so you need the OCaml Platform[1] tooling to install and use it.
This way, you get all the benefits of having a native toolchain and build system, and a great integration with modern JavaScript with e.g. npm or yarn.
The challenge with ReScript is that the authors really were focusing on the JS ecosystem, and didn't care at all about OCaml. Their fusion with the ReasonML community didn't make a whole lot of sense. ReScript is a much better language now that it has split than it was then, if you look solely through the lens of a better JS.
But, as Elm and other compiled-to-JS languages have learned, Typescript has gotten good enough that other languages might not be sufficiently better than TS to attract enough interest to have a vibrant community. Doubly so since the JS-interop story isn't nearly as good in ReScript as it is in Typescript (though it's much much better than in Elm).
However, the aim of writing programs in OCaml which compile to nice JS and also native OCaml, and allowing both client and server to be written in OCaml, remains valid and interesting (and I would argue was held back by js_of_ocaml, the pre-existing way to do it). So I think there is something interesting here, though it isn't a ReScript competitor except tangentially.
Though I cannot really understand where ReasonML (a JS-like syntax for OCaml) fits into this - if the target is OCaml devs, than surely the ReasonML syntax stuff is not valuable anymore?