Melange

OCaml for JavaScript developers

Melange is a backend for the OCaml compiler that emits JavaScript. Melange strives to provide the best integration with both the OCaml and JavaScript ecosystems. To know more about it start by reading the introductory tutorial, then check the Learn section for more information.

Features

A Solid Type System

Melange leverages OCaml's powerful type system to catch more bugs at compile time. Large, complex codebases become easy to maintain and refactor.

First-Class Editor and Tooling

Melange fully utilizes the power of the OCaml Platform to provide integrations with editors such as VSCode, Vim, or Emacs, with features like type inspection, autocomplete, and more. It also has first-class integration with Dune, OCaml's most used build system.

JavaScript Integration

Whether you want to use existing JavaScript packages from NPM, or use your own JavaScript libraries in your projects, Melange has you covered. With an expressive bindings language, and an ergonomic compilation model, Melange can help you build robust applications that leverage functionality from the JavaScript ecosystem.

Stable and Industry Backed

Melange builds on top of decades of type system research, compiler engineering and tooling development to provide a polished developer experience. Companies like Ahrefs use Melange daily to deploy web applications for their users.

What is Melange

Melange is a set of tools that come together to generate and interoperate with modern JavaScript:

  • The compiler libraries: These libraries are a fork of the OCaml compiler libraries with adaptations for generating lean JavaScript code, as opposed to bytecode or assembly.

  • The compiler (melc): This executable takes OCaml code as input and is responsible for generating JavaScript. It relies on the Melange compiler libraries.

  • The runtime: This is a small code component essential for running JavaScript programs produced by the compiler.

  • The standard libraries: Melange includes a set of foundational elements such as data structures, functions, and bindings to JavaScript APIs, all aimed at helping developers accelerate app development.

  • The preprocessor (melange.ppx): This is a meta-programming tool designed to preprocess Melange programs, simplifying code generation for common use cases like generating bindings or code from types.

  • The playground: This is a browser-based version of the compiler, enabling users to experiment with and share Melange code snippets and small programs.

In addition to these core components, there is an ongoing effort to integrate Melange into the broader OCaml Platform and other tools and libraries within the OCaml ecosystem:

  • A build system: Dune, a prominent OCaml build system, provides seamless support for Melange.

  • A package manager: Melange seamlessly integrates with opam, OCaml's default package manager.

  • A package repository: Melange libraries and tools are published in the main public package repository for opam.

  • Syntaxes: Melange empowers users to optionally write their applications using the Reason syntax, with full support for React applications through the Melange bindings library ReasonReact.

  • Editor integration: Melange is fully compatible with the OCaml editor tools, and also with code formatters like ocamlformat and refmt.