package mlx

  1. Overview
  2. Docs
OCaml syntax dialect which adds JSX syntax expressions

Install

dune-project
 Dependency

Authors

Maintainers

Sources

mlx-0.11.tbz
sha256=bea6b7e57deb13a1cc20af3fe9101b90b77d3e886097c6d44dd63eb96f5aaceb
sha512=a73d0b22f99709be9f0d2753372b43198a4e064a318f22ea68f37e965baa7a0b1b43f43b15e043f556c8d15e5475e31eb039472aa33aeceeee76ec68eca3e7fb

Description

Published: 28 Dec 2025

README

mlx

An OCaml syntax dialect which adds JSX expressions to the language.

let header ~title () =
  <header>
    <h1>title</h1>
  </header>

let page =
  <html>
    <body>
      <header title="Hello, world!" />
      <div>
        "Some content goes here"
      </div>
    </body>
  </html>

This code is transformed into the following OCaml code:

let header ~title () =
  header () ~children:[ h1 () ~children:[ title ] [@JSX]; ] [@JSX]

let page =
  html () ~children:[
    body () ~children:[
      header () ~title:"Hello, world!" [@JSX];
      div () ~children:[ "Some content goes here" ] [@JSX];
    ] [@JSX];
  ] [@JSX]

It is expected to use mlx-pp preprocessor with either a runtime lib which provides the implementation of such functions or a ppx which which further transforms [@JSX] attributes into the desired output.

Installation & Usage

Use the following commands to install the necessary packages:

opam install mlx ocamlmerlin-mlx

To make dune consider .mlx files as OCaml files you need to configure an mlx dialect, put this in your dune-project file:

(dialect
 (name mlx)
 (implementation
  (extension mlx)
  (merlin_reader mlx)
  (preprocess
   (run mlx-pp %{input-file}))))

Editor Support

VS Code

For VSCode and its forks (Cursor, Windsurf, etc.), install the Official OCaml Platform extension (version 2.0.0 or higher). It supports mlx syntax highlighting and all LSP features on par with .ml files.

Neovim

For Neovim users, install plugin: https://github.com/ocaml-mlx/ocaml_mlx.nvim

  • Example with Dream web framework: https://github.com/aantron/dream/pull/330
  • Template ReasonReact project: https://github.com/andreypopp/melange-mlx-template
  • mlx announcement on OCaml Discourse: https://discuss.ocaml.org/t/ann-mlx-syntax-dialect/15035

Dependencies (3)

  1. dune >= "3.16"
  2. ppxlib >= "0.34.0"
  3. ocaml >= "4.14.0"

Dev Dependencies (4)

  1. odoc with-doc
  2. ocaml-lsp-server with-dev-setup
  3. ocamlformat with-dev-setup
  4. menhir = "20201216" & with-dev-setup

Conflicts

None