OCaml Environment

(version française)

This page gathers some instructions/suggestions for working comfortably with OCaml, whether at X in computer rooms or on your machines.

1. In salles info at X

Here are instructions to setup opam and then install a few OCaml libraries on your X account in salles info. Note that several of the following commands require confirmation with a line like:
> Do you want to continue? [Y/n]
You must answer "y" (yes) to confirm, or "n" (no) to cancel, then press Enter. The capital letter indicates the default choice if you simply press Enter. Therefore, you must run the commands given below one by one and check if any questions are asked!

Before using opam for the first time, it must be initialized. To do this, run the following commands:

opam init -y
eval $(opam env)
You can then install opam packages using the command opam install. Install the packages that will be useful for the course:
opam install menhir merlin graphics dune ocamlformat tuareg ocp-index user-setup
opam user-setup install
eval $(opam env)
To use Down (toplevel enhancement; does not work under Windows):
opam install down
touch ~/.ocamlinit && echo '#use "down.top";;' >> ~/.ocamlinit
You can now work comfortably with OCaml, using any editor. If you wish to use Visual Studio Code, you must follow the instructions below.

Visual Studio Code

Visual Studio Code is pre-installed on the machines at École Polytechnique. (If you are using your own machine, you will need to install it first.)

Start by installing an opam package that VS Code will need:

opam install ocaml-lsp-server

You can launch VScode by clicking on its icon or with the command

code
Click on the icon and search for the "OCaml Platform" extension by typing "OCaml" in the search bar. Install it.

Click on "Open folder" and choose a folder to work in, for example td2 (create it if necessary with the icon in the top right of the file selector).

Add a file to your working directory (for example, test.ml). It should be recognized as an OCaml file (small orange icon with a camel). It is typed on the fly, and types/errors are displayed.

To run an OCaml program, open a new terminal (Terminal menu) and then run a command such as:

ocamlopt test.ml -o test && ./test

2. On your machine

Below are platform-specific instructions. Then, you can follow the instructions in Part 1 for opam and Visual Studio Code.

Windows

Follow the installation instructions on the page Install OCaml on Windows.

An alternative is to install WSL (Windows Subsystem for Linux).

Linux, macOS, or *BSD

Follow the installation instructions on the page Install OCaml on Linux, macOS, or *BSD.
back to the main page