This page gathers some instructions/suggestions for working comfortably with OCaml, whether at X in computer rooms or on your machines.
> 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";;' >> ~/.ocamlinitYou can now work comfortably with OCaml, using any editor. If you wish to use Visual Studio Code, you must follow the instructions below.
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
codeClick 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
An alternative is to install WSL (Windows Subsystem for Linux).