[HN Gopher] Melange 1.0: Compile OCaml / ReasonML to JavaScript ___________________________________________________________________ Melange 1.0: Compile OCaml / ReasonML to JavaScript Author : anmonteiro90 Score : 162 points Date : 2023-06-12 16:28 UTC (6 hours ago) (HTM) web link (buttondown.email) (TXT) w3m dump (buttondown.email) | colesantiago wrote: | Do I need OCaml installed to use this, why not a single binary? | anmonteiro90 wrote: | 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. | | [1]: https://ocaml.org/docs/platform | js_of_ocaml_3 wrote: | 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. | | Elm & PureScript I believe solved this problem. | yawaramin wrote: | OCaml's object types solve exactly this problem. And they have | been around since Caml became OCaml. | arxanas wrote: | 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? | pbiggar wrote: | 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? | square_usual wrote: | 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! | anmonteiro90 wrote: | Hi 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 | m0meni wrote: | 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. | anmonteiro90 wrote: | Thank you :-) | | 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]. | | [1]: https://github.com/reasonml/reason/pull/2605 [2]: | https://tech.ahrefs.com/ahrefs-is-now-built-with- | melange-b14... | meitros wrote: | Out of curiosity, what do you think the issues with js_of_ocaml | were? | pbiggar wrote: | 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) | tylerag wrote: | In 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-resc... | davesnx wrote: | It's a good idea to read "A bit of history" under Melange docs: | https://melange.re/v1.0.0/rationale/#a-bit-of-history | thangngoc89 wrote: | 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 | k__ wrote: | 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. | sp33der89 wrote: | 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. | davesnx wrote: | With 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 wrote: | 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. | | [1]: https://github.com/reasonml/reason [2]: | https://ocaml.org/docs/platform | cassepipe wrote: | Sorry if I am being pedantic but isn't it (confusingly) | Reason (the new syntax) and not ReasonML (the organization) ? | Taikonerd wrote: | I'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/ | | If you want to revitalize the project, please start updating | the blog again :-) | gdsdfe wrote: | this is all very confusing | Mimmy wrote: | 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 | davesnx wrote: | Biased 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. | Weebs wrote: | 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 | square_usual wrote: | 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. | orra wrote: | 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. | ekosz wrote: | Interesting to see oh this will affect (or not) the Rescript | project. | chrischen wrote: | I'm using both, with with Rescript primarily on the front-end | and Melange on the backed... both targeting JS/NodeJS. | anmonteiro90 wrote: | Melange 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 [2]: | https://tech.ahrefs.com/ahrefs-is-now-built-with-melange-b14... | freedomben wrote: | Great work on this write-up! Super informative and well | written. It's refreshing to read posts like this | fredrikholm wrote: | 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. | | Thank you! | paulsb wrote: | And Dream is being actively developed again: | https://aantron.github.io/dream/ | cassepipe wrote: | Maybe will Onivim rise from the dead too ? Who knows | asycocaml wrote: | Can someone please expain the state of doing async with Melange? | ReasonML never had an answer in that important area to my | knowledge. | cassepipe wrote: | Congrats on the releases ! I have been waiting for this make it | to 1.0 for some time now. That's a pleasant suprise. ___________________________________________________________________ (page generated 2023-06-12 23:00 UTC)