bryan garza
Adding Syntax Extensions To An OCaml Project 2016-02-08

Table of contents

Here's the set of steps needed to start using syntax extensions. I'll be using sexplib as the example.

First, you have to add the extension to your .merlin file:

PKG core yojson lwt cohttp cohttp.lwt
EXT sexplib.syntax

Now Merlin's minor mode won't throw up errors when you save. Next up is compiling the project. I'm using Oasis. Add sexplib and its .syntax file to the BuildDepends in the _oasis file:

(other stuff)

Executable myprogram
  Path: src
  BuildTools: ocamlbuild
  MainIs: main.ml
  CompiledObject: best
  BuildDepends:
    core,
>   sexplib,
>   sexplib.syntax,
    threads,
    yojson,
    lwt,
    cohttp,
    cohttp.lwt

After that, call oasis to add in the new dependencies. I use

oasis setup -setup-update dynamic

Run make again, and the project should build using sexplib!