Published on

Introducing Melange 2.0

Authors

Today, the Melange team is excited to introduce Melange 2.0. This iteration brings an upgrade to the OCaml 5.1 type checker, along with increased compatibility with the OCaml Platform. Melange 2.0 unifies the compiler attributes and libraries under the Melange brand and it improves developer experience across the ecosystem. We're also publishing a few battle-tested libraries to OPAM.


Everything we have included in this release has been designed to enhance your experience writing Reason / OCaml for modern JS workflows. Here's a comprehensive look at what's new.

What's New in Melange 2.0?

OCaml 5

OCaml 5.1 has just been released. Melange 2.0 has been upgraded to use the newly released OCaml 5.1 type checker and compiler libs. As the OCaml community starts to upgrade to the newest version of OCaml, Melange will be co-installable in your OPAM switch.

While the Melange type checker has been upgraded to the 5.x release line, Melange doesn't yet include support for effect handlers and some of the multicore OCaml primitives. Stay tuned for future updates on this.

The reign of melange.ppx

The compiler frontend transformations related to the FFIextensions and derivers have been fully extracted from the compiler to the Melange PPX. Going forward, it's likely you'll need to preprocess most Melange code with melange.ppx.

Wrapping the Melange Core Libraries

In this release, we wrapped the Melange runtime and core libraries. Each library exposes only a single top-level module, avoiding namespace pollution. The only modules exposed by Melange are now:

  • The Js module contains utilities to interact with JavaScript standard APIs. Modules such as Js_string now only accessible via Js.String.

  • The Belt library contains utilities inherited from BuckleScript. Its sub-modules similarly nested under Belt, e.g. you'll use Belt.List instead of Belt_List.

  • Melange 2.0 exposes only a single Stdlib module, where previously it was leaking e.g. Stdlib__String, etc.

  • New libraries: The Node module has been extracted to a new melange.node library. Similarly, Dom is now only accessible via the melange.dom library. Both libraries are released with the Melange distribution, but not included by default; they can be added to the Dune (libraries ...) field.

Enforcing the Melange brand

bs.* attributes have been deprecated in this release in favor of mel.*. The uncurried [@bs] attribute is now simply [@u]. The next major Melange release will be removing them entirely. %bs.* extension nodes have, however, been replaced with %mel.* due to limitations in ppxlib. This is a breaking change.

Development experience

We've done significant work making Melange easier to use in this release:

  1. Attributes like [@{bs,mel}.val] have been deprecated as they're redundant in the Melange FFI.

  2. We're introducing more ways of using @mel.as in:

    1. let bindings to allow exporting otherwise invalid OCaml identifiers;

    2. external polymorphic variants without needing to use [@mel.{string,int}];

    3. inline records in both regular and extensible variants and custom exceptions.

Ecosystem

  • With this release, we're starting to publish some widely used libraries from the melange-community and ahrefs organizations. Be on the lookout for new Melange-ready releases popping up in the OPAM repository in the next few days. Reason 3.10 is also a companion release to Melange 2.0.

  • The new reason-react releases greatly increase developer experience by improving the editor integration. React props and children now point to the correct source code locations, making React components much easier to track in your editor.

  • We've also released an OPAM plugin, check-npm-deps. This tool checks whether the NPM dependencies in your node_modules folder match what libraries released to OPAM need. check-npm-deps is currently in preview and we're looking for your feedback on how we can evolve it.

Support & Sponsorship

This release was made possible with the continued support of:

Parting thoughts

The goal of Melange is to provide a robust and evolving toolchain that matches the dynamic nature of modern JS development. Melange 2.0 is a testament to that commitment. In this release, we've shipped the majority of our Q3 roadmap. Dive in, explore the new features, and let us know your feedback.

Consult the full change log and the migration guide from 1.0 for a more detailed look at all the changes that went into this packed release.

If you or your company are interested in seeing what Melange can do for your JavaScript needs, feel free to get in touch. We'd love to hear from you.

Happy hacking!

Antonio & the Melange team