Date Tags ocaml

When developing ocaml applications I often need to load a bunch of libraries in my toplevel to test a small function. This can be a tedious task when you have a complex project and a lot of libraries installed in your system. In the ocaml doco, kind of buried in the middle of a section there is the solution to this problem : .ocamlinit .

On start-up (before the first phrase is read), if the file .ocamlinit exists in the current directory, its contents are read as a sequence of Objective Caml phrases and executed as per the #use directive described in section 9.2. The evaluation outcode for each phrase are not displayed. If the current directory does not contain an .ocamlinit file, but the user’s home directory (environment variable HOME) does, the latter is read and executed as described below.

so for example if you often use ocamlfind-aware libraries and extlib in particular (I know, batteries… I know…) you can simple put these two lines in the .ocamlinit in your home directory.

#use "topfind";;
#require "extlib";;

and next time you fire the toplevel :

        Objective Caml version 3.11.2

Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

/usr/lib/ocaml/extlib: added to search path
/usr/lib/ocaml/extlib/extLib.cma: loaded
# 

As the documentation says you can have an .ocamlinit file in the directory of your project to load specific libraries.