9 ms·
Melange 1.0: Compile OCaml / ReasonML to JavaScript
- ekosz 3y agoInteresting to see oh this will affect (or not) the Rescript project.
- anmonteiro90 3y agoMelange and ReScript target different audiences. 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. [1]: https://ocaml.org/docs/platform https://ocaml.org/docs/platform [2]: https://tech.ahrefs.com/ahrefs-is-now-built-with-melange-b14f5ec56df4 https://tech.ahrefs.com/ahrefs-is-now-built-with-melange-b14...
- freedomben 3y agoGreat work on this write-up! Super informative and well written. It's refreshing to read posts like this
- chrischen 3y agoI'm using both, with with Rescript primarily on the front-end and Melange on the backed... both targeting JS/NodeJS.
- colesantiago 3y agoDo I need OCaml installed to use this, why not a single binary?
- anmonteiro90 3y agoMelange 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. [1]: https://ocaml.org/docs/platform https://ocaml.org/docs/platform
- tylerag 3y agoIn the unlikely event you are confused on the difference between ReScript, Reason, and ReasonML, I recommend this post: https://ersin-akinci.medium.com/confused-about-rescript-rescript-reason-reasonml-and-bucklescript-explained-ab4230555230 https://ersin-akinci.medium.com/confused-about-rescript-resc...
- davesnx 3y agoIt's a good idea to read "A bit of history" under Melange docs: https://melange.re/v1.0.0/rationale/#a-bit-of-history https://melange.re/v1.0.0/rationale/#a-bit-of-history
- sp33der89 3y agoWhat 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.
- davesnx 3y agoWith Melange ReasonML has a small comeback, since Melange and dune supports it out-of-the-box. There has been a bit of activity on fixing bugs on refmt and polish the experience, no plans for big features so far but we will keep working on it. We will update documentation from either reason-react and reason to highlight the integration with Melange soon.
- anmonteiro90 3y agoReasonML 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. [1]: https://github.com/reasonml/reason https://github.com/reasonml/reason [2]: https://ocaml.org/docs/platform https://ocaml.org/docs/platform
- Taikonerd 3y agoI'm glad to hear that! I had thought ReasonML was dead, because the blog hasn't been updated since 2018: https://reasonml.github.io/blog/ https://reasonml.github.io/blog/ If you want to revitalize the project, please start updating the blog again :-)
- cassepipe 3y agoSorry if I am being pedantic but isn't it (confusingly) Reason (the new syntax) and not ReasonML (the organization) ?
- Weebs 3y agoI 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
- orra 3y agoI'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.
- square_usual 3y agoMe 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.
- phforms 3y agoI 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.
- pbiggar 3y agoWhen 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?
- swuecho 3y agoWhat is your journey about F# and Fable? I find Fable is good too and generated code is very readable.
- square_usual 3y agoI 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!
- anmonteiro90 3y agoHi Paul, appreciate the kind words. 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). [1]: https://www.youtube.com/watch?v=ROor6_NGIWU https://www.youtube.com/watch?v=ROor6_NGIWU
- thangngoc89 3y agoCongratulations 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
- gdsdfe 3y agothis is all very confusing
- cassepipe 3y agoCongrats on the releases ! I have been waiting for this make it to 1.0 for some time now. That's a pleasant suprise.
- Mimmy 3y agoMight 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 https://news.ycombinator.com/item?id=17910069
- davesnx 3y agoBiased answer: 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.
- rtpg 3y agoClojurescript 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
- fredrikholm 3y agoFirst 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. Thank you!
- js_of_ocaml_3 3y agoA 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. Elm & PureScript I believe solved this problem.
- yawaramin 3y agoOCaml's object types solve exactly this problem. And they have been around since Caml became OCaml.
- arxanas 3y agoWhy 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?
- k__ 3y agoAs 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.
- ElFitz 3y agoThat’s the tragedy and part of the strength of open source. Some people are just bent on doing their thing, the way they want it. I prefer the current situation to the one where the ReScript people took over Reason and changed its focus and syntax.
- nerdponx 3y agoWasn't there also another OCaml-to-Javascript compiler called called js_of_ocaml?
- LeonidasXIV 3y agoThere was and still is. It is actively maintained, works fairly well and has even recently been extended with support for multicore.
- reycharles 3y agoIndeed, and I believe it predates all the other ones by quite a bit.
- KRAKRISMOTT 3y agoThe 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.
- asycocaml 3y agoCan someone please expain the state of doing async with Melange? ReasonML never had an answer in that important area to my knowledge.
- chrischen 3y agoYou 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.
- emmelaich 3y agoJust a note, melange is also the name of a computer language workbench from INRIA (http://melange.inria.fr/ http://melange.inria.fr/) and an APK builder (https://edu.chainguard.dev/open-source/melange/overview/ https://edu.chainguard.dev/open-source/melange/overview/) Both of those came up before melange.re when searching for a hello world example.
- danieloro515 3y agoThanks 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.
- idkjs 3y agoGreat new. Congratulations to the Melange team. Keep on keeping on.