Interested in Bucklescript? You should be. It’s OCaml that compiles to JavaScript. But unlike most compile-to-JS langauges, it’s really, really good. Fast. Produces small, legible JavaScript. And it’s got some of the best type inference in the business.

Here’s how I got up and running on my Mac.

Install OCaml and friends

First, install OCaml. On Mac, this is done like so:

brew install ocaml
brew install opam
opam install merlin utop ocp-indent

Opam is the package manager (e.g. like NPM, gems, nuget) for OCaml.

  • utop: a really, really nice REPL.
  • merlin: a sweet tool for adding IDE-like features to VSCode, vim, etc
  • ocp-indent: a tool for helping auto-indent your .ml files

Setup VS Code:

Set up BuckleScript

mkdir avl
cd avl
npm init
npm install --save bs-platform

Edit package.json and make scripts look like this:

"scripts" : {
    "build" : "bsc -c"

Test that it all works

Create and make it look like this:

let () =
  print_endline "hello world"


npm run build
node hi.js

You should see “hello world” get printed.