TL;DR - run the following:
Add the following to your ~/.bashrc (or equivalent):
Initialize opam
OPAM will print some introductory information and ask if you would like it to update ~/.bashrc and ~/.ocamlinit
for environment configuration. Type 'y'.
Now a default version of the compiler is installed.
To view other available compiler versions, run:
To install the latest version of the compiler (4.02.3 as of 2015-10-16), use the following:
To change your path to the newly built compiler, run:
I recommend adding this to your ~/.bashrc or equivalent.
TL;DR - three packages are essential: core, ounit and utop
OCaml comes with a standard library that is kept small.
There are several alternatives open-source standard libraries that are easily installable.
The first is Jane Street Core.
The other primary library (that I know of) is Batteries
I prefer Core over Batteries (as do the authors of Real World OCaml).
After you've installed a better standard library, I recommend installing OUnit, a testing framework.
Finally, while OCaml comes with a repl, "top", there is a better version available: utop.
Core + utop will actually give you an even better REPL: coretop.
coretop is utop except that it already knows about the Core library.
TL;DR -don't call ocamlc directly; use ocamlbuild with -use-ocamlfind TARGET.byte
Use Makefiles to automate steps of workflow.
See here for an example of both.
An OCaml installation comes with two versions of the compiler: ocamlc and ocamlopt.
ocamlc generates byte code, whereas ocamlopt generates a native binary.
I recommend using ocamlbuild for building
your projects. It can manage dependencies and pick the appropriate compiler.
Example: suppose I have a file named foo.ml, the module interface is in foo.mli and it uses the Core library.
The following commands will, respetively build bytecode and native binaries:
I typically try to divde my project into separate modules, each with their own directory, Ocaml module, tests and Makefile.
Makefiles are very useful for quickly invoking different commands in the OCaml toolchain.
I've provided an example Makefile I use as a gist
Other Tools to be Aware of
Here are some cool sounding tools I'm aware of, but have not yet taken the time to use.
Merlin - From the site: "Merlin is an editor-independent tool to ease the developpement of programs in OCaml"