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 -version
and make sure you have a response. -
Next up, we need to configure OPAM. Run
opam init
and walk through the questions. I answered yes to everything. -
Now we need some packages. We’re going to start by installing just
Core
andutop
.Core
is 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 forContainer
structures. To be honest, we could just installBase
instead ofCore
, whereBase
supplies those features, but RWO usesCore
so let’s stick with it.utop
is 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 useBase
orCore
so you can omit it. -
Let’s also install
dune
for our build tooling, withopam install dune
. -
open up
~/.ocamlinit
and add the following to get all ofCore
set 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.