Crafting Interpreters in OCaml - Setting up your environment
May 15, 2019
If you want to just clone a repo and move on, check out this sample
The easiest way to get an environment set up is to just follow the Real World OCaml guide. I’m going to enumerate the steps here in less detail. Since I’m running on macOS, this guide will be tailored to that. Check out the RWO guide for more options.
-
Get OPAM installed. Opam is the OCaml package manager and is available on Homebrew. If you have Homebrew installed, it’s as easy as
brew install opam -
This should have installed OCaml for you. To check, run
ocaml -versionand make sure you have a response. -
Next up, we need to configure OPAM. Run
opam initand walk through the questions. I answered yes to everything. -
Now we need some packages. We’re going to start by installing just
Coreandutop.Coreis a replacement to the OCaml standard library. It has some different APIs for labeled arguments, more functionality in every module, and has a consistent interface forContainerstructures. To be honest, we could just installBaseinstead ofCore, whereBasesupplies those features, but RWO usesCoreso let’s stick with it.utopis a toplevel (like the Ruby REPLirb) that is really easy to work with for testing code on the fly. For the purpose of this tutorial, I’m actually not going to useBaseorCoreso you can omit it. -
Let’s also install
dunefor our build tooling, withopam install dune. -
open up
~/.ocamlinitand add the following to get all ofCoreset up in the toplevel
#use "topfind";;
#thread;;- Configure your editor. I use Visual Studio Code and really like the ReasonML tool
Reason Language Server
And that’s a minimal install! If you check out the repo I linked above, you can run tests with dune runtest and play with some code.
I work and live in Brooklyn, NY building software.