Melange is a compiler for producing performant JavaScript from Reason and OCaml. Powered by a strong static type system with best-in-class type inference based on the OCaml compiler, Melange facilitates producing robust JavaScript code.
This project is forked from the ReScript compiler shifting focus to integrating with the OCaml ecosystem. This enables code sharing between backend and frontend using Dune's virtual libraries.
Melange also introduces a ReScript compatibility layer to maintain compatibility with ReScript's Syntax - preserving access to ReScripts ecosystem of packages.
Write in Reason/OCaml, use OCaml libraries or ReScript packages to kickstart your project!
A small write-up with more details on the motivation behind this project can be found in this blog post.
This project is currently unreleased. There are, however, a few ways to try it out.
The easiest way to get started is to
clone the basic template
and run esy
in the project root. To install Esy, npm install -g esy
should cover most workflows. If you have NodeJS / npm
available, npx esy
is even shorter.
Melange has good support for Nix:
nix run github:melange-re/melange -- build
runs melange.nix shell github:melange-re/melange -c $SHELL
enters a shell withmel
andmelc
in$PATH
. Try outmel --help
, for example. for available options.- Adding
github:melange-re/melange
as a flake input exports melange as the default package
Please reach out on the ReasonML Discord if you can't figure it out!
Until Melange has first-class support in Dune, ocaml-lsp
support relies on
having Melange generate a .merlin
file to provide the language server with
information about your project.
To enable editor support via ocaml-lsp
, add the following to your esy.json
:
// esy.json
{
"devDependencies": {
"@opam/ocaml-lsp-server": "ocaml/ocaml-lsp:ocaml-lsp-server.opam#c275140",
"@opam/dot-merlin-reader": "*"
}
}
Then use the --fallback-read-dot-merlin
flag when running ocaml-lsp
.
If using the VSCode OCaml
Platform extension, use the
Custom
sandbox option and provide the flag to ocaml-lsp
via the command
template:
// .vscode/settings.json
{
"ocaml.sandbox": {
"kind": "custom",
"template": "esy $prog $args --fallback-read-dot-merlin"
}
}
The current Melange distribution works on OCaml 4.14 and OCaml 5.00+trunk. If
you need to use Melange with OCaml 4.12 (the only formerly supported version),
you can consume the 0.1.0 tag
for this repo (make sure to similarly use the 4.12.0+mel
tag
for melange-compiler-libs
).
Name | Purpose | Dependencies | Notes |
---|---|---|---|
Esy | Package manager | Installed with NPM | Obtaining dependencies (e.g. dune or reason ) |
Dune | Build tool | Installed with esy |
Well-known OCaml build tool; supports custom rules that can be composed to build anything |
Reason | Syntax | Installed with esy |
a library that implements an alternative syntax to OCaml |
Melange | Compiler that emits Script | Esy (to install), Dune (to build), Reason (used as a library) | Supports OCaml, Reason and ReScript syntaxes; derived from ReScript, focused on compatibility with the wider OCaml ecosystem |
ReScript | The brand around a syntax and a compiler that emits JavaScript | None | Distributed via NPM as prebuilt binaries; previously called BuckleScript |
Yes! ReScript syntax is supported, but ReScript won't have as many features as
the OCaml or Reason syntaxes due to ReScript being built on top of an old OCaml
version (4.06 - Released 2018).
(e.g. letop
binding operators,
generalized module open expressions,
or local substitutions in signatures).
Upstream removed the refmt
flag, which used to allow configuring the path to a custom Reason binary. This
was a welcome change for this repo too, so we cherry-picked it. The rationale:
this project uses Reason as a library,
so you can simply depend on the Reason version that you'd like in the usual way,
via your preferred package manager.
See CONTRIBUTING.md.
- Thanks to the ReScript project, its author and maintainer @bobzhang, and its many contributors. Melange is a fork of ReScript, and continues to incorporate patches to ReScript on a regular basis.
- Thanks to the OCaml team, obviously, without such a beautiful yet practical language, this project would not exist.
- Thanks to Bloomberg and Facebook. The ReScript project began at Bloomberg and was published in 2016; without the support of Bloomberg, it would not have happened. ReScript was funded by Facebook since July 2017.
See also Credits.md concerning some individual components of Melange.
See COPYING and COPYING.LESSER
See Credits for more details.