Bryan Garza

Adding Syntax Extensions To An OCaml Project ( February 8, 2016)

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!

Archive