package mel
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=2e74738f624bec755860f09eeb4f446fec16290ab5c5db452645ba003c7b6d14
sha512=0c45111206dd8e4684e3036788f9ef352b3dddff55705a21c1d04271438a5d0166322e43eefe517d68c9c00390cf5bdb2d166dd2537c38f8af8815718bac0b4a
Description
Published: 24 Nov 2022
README
Melange
Melange compiles OCaml / Reason to JavaScript
Powered by the versatile OCaml type system, with best-in-class type inference, Melange produces robust JavaScript code.
Installation
Melange is released to OPAM. You can obtain it in multiple ways:
OPAM
$ opam install melTemplate
melange-re/melange-opam-template provides a GitHub template repository that can be used as a project starter.
Note: mel build builds a Melange project. Before running the resulting JavaScript, the Melange runtime library needs to be present in node_modules so that it can be found by JavaScript based tooling:
ln -sfn $(opam var prefix)/lib/melange/runtime node_modules/melangeManual setup
After installing Melange, you should now be able to run mel from your switch:
$ opam exec -- mel --helpEsy
Get Esy on NPM:
npm install -g esyinstalls Esy globally- if
npmis installed,npx esycan be used to run Esy locally
An Esy project starter also exists to get started quickly with Esy.
Once the repository has been cloned, run esy in the project root.
Nix
Melange has good support for Nix:
nix run github:melange-re/melange#mel -- --helpruns melange.nix shell github:melange-re/melange#mel -c $SHELLenters a shell withmelandmelcin$PATH. Try outmel --helpfor available options.github:melange-re/melangecan be added as a flake input
OCaml version compatibility
The current Melange distribution targets OCaml 4.14. There's an old version of Melange based on OCaml 4.12 that requires version 4.12.0+mel of melange-compiler-libs.
Editor integration
Until Melange has first-class support in Dune, editor integration is based on a
.merlinfile workflow.- Melange generates
.merlinfiles automatically as part of the build
- Melange generates
ocaml-lspbased Language Server Protocol support needs to be configured as follows:
OPAM
Install ocaml-lsp and dot-merlin-reader:
$ opam install ocaml-lsp dot-merlin-readerEsy
Add the following to esy.json:
// esy.json
{
"devDependencies": {
"@opam/ocaml-lsp-server": ">= 1.12.0",
"@opam/dot-merlin-reader": "*"
}
}Pass --fallback-read-dot-merlin to ocaml-lsp
ocaml-lsp requires the --fallback-read-dot-merlin flag to look for .merlin files.
VSCode
- Install the VSCode OCaml Platform extension
- Select the "Custom" sandbox option and provide the flag to
ocaml-lspvia the following command template:
// .vscode/settings.json
{
"ocaml.sandbox": {
"kind": "custom",
"template": "esy $prog $args --fallback-read-dot-merlin"
}
}Community
- There's a
#melangechannel in the ReasonML Discord
FAQ
How does this project relate to other tools?
This project is forked from the ReScript compiler, focused on a deeper integration with the OCaml ecosystem. This allows sharing code between backend and frontend using Dune's virtual libraries.
Melange also introduces a ReScript compatibility layer to maintain compatibility with ReScript syntax - preserving access to ReScript's package ecosystem.
A small write-up with more details on the motivation behind this project can be found in the announcement blog post.
Below is a quick comparison between Melange and other tools:
Name | Purpose | Dependencies | Notes |
|---|---|---|---|
Package manager | Installed with NPM | Obtaining dependencies such as | |
Package manager | None | Obtaining dependencies such as | |
Build tool | Installed with e.g. | Composable build tool for OCaml; supports composing custom rules to build any project | |
Syntax | Installed with e.g. | Alternative syntax to OCaml | |
Compiler that emits Script | Esy / OPAM (to install), Dune (to build) | Supports OCaml, Reason and ReScript syntax; derived from ReScript, focused on deeper integration with OCaml | |
The brand around a syntax and a compiler that emits JavaScript | None | Distributed via NPM as prebuilt binaries; previously called BuckleScript |
Can I use ReScript syntax?
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 in 2018). (e.g. letop binding operators, generalized module open expressions, or local substitutions in signatures).
Contributing
See CONTRIBUTING.md.
Acknowledgments
- 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.
Licensing
See COPYING and COPYING.LESSER
See Credits for more details.