OCaml Batteries Included

# Installing Batteries Included

## The GODI package manager

At the moment, on most computers, the easiest manner of installing OCaml Batteries Included on your computer is to take advantage of GODI , a package manager specifically dedicated to OCaml. You will first need to install GODI, if GODI isn't install on your machine yet, then to select package `batteries` in the list of packages and accept the decisions of GODI. This should take care of installing OCaml Batteries Included for you.

Note that producing the documentation is long (typically 10-15 minutes).

## Fedora / Debian / Red Hat / Ubuntu

At the time of this writing, this method is experimental.

On Fedora / Debian / Red Hat / Ubuntu stations, packages may be able for Batteries. If this is the case, to install OCaml Batteries Included, just run your usual package manager (generally either Synaptic, Yum, KPackage, Aptitude or DSelect), and select package `libbatteries-ocaml-dev`. This should take care of installing OCaml Batteries Included for you.

## Manually

To perform installation of OCaml Batteries Included manually, please make sure that you have already installed all the following tools and libraries:

- OCaml itself, version 3.11 or greater
- Findlib, version 1.2.5 or greater
- Camomile, version 0.7 or greater
- GNU Make
- OUnit (optional, to run tests)
- Ocaml-benchmark (optional, to run benchmarks)

Once all these libraries are installed, you may download and uncompress the latest version of OCaml Batteries Included, enter the directory produced by decompression and invoke

    make all install doc install-doc

to build and install both the byte-code version, the native version and the documentation of OCaml Batteries Included.

# Using Batteries Included

## Interactive environment

To use batteries in the ocaml toplevel, open a terminal and write `ocamlfind batteries/ocaml` , or if you have `rlwrap` installed, `rlwrap ocamlfind batteries/ocaml` for readline enabled command editing. Alternatively, install `ocamlinit` from the batteries source directory into your `~/.ocamlinit` file and launch ocaml normally `ocaml` .

## Compiling with Batteries

File `doc/batteries/myocamlbuild.ml` is an extension of OCamlBuild. It defines tags, which you may use in your projects to specify that your project should take advantage of the various features of Batteries Included. Copying this file to your project directory is required to take advantage of these tags.
The tags defined by Batteries Included are:

pkg_threads
  Allow threading. Required to use module `Control.Concurrency.Threads`.
pkg_batteries
  Use Batteries Included only as a library. No language extension is involved. To use the features of Batteries Included with `pkg_batteries`, you need to start your files with `open Batteries_uni` if not using threads or `open Batteries` if using threads.
pkg_batteries.syntax
  Use Batteries Included libraries with the syntax extensions. To use the library features of Batteries Included with `pkg_batteries`, you need to start your files with `open Batteries_uni` if not using threads or `open Batteries` if using threads.

To take advantage of a tag for a file or a set of files, you need to add this tag to a speciale file named `_tags`, placed in the same directory as your files. For instance, to have `my_file.ml` compiled with Batteries Included as a library and `my_other_file.ml` compiled with both the library, the language extensions and boiler-plate code, your file `_tags` should read:

    <my_file.ml>: pkg_batteries
    <my_other_file.ml>: use_batteries,use_boilerplate

The order of lines doesn't matter, nor does the order of tags on one line. For more informations on `myocamlbuild.ml` and `_tags`, see the documentation of OCamlBuild.

## More control over compilation

During its installation, Batteries Included creates a set of findlib packages:

batteries
  The main package for Batteries Included. In turn, this package defines subpackages
batteries.pa_comprehension.syntax
  A language extension for list comprehension.
batteries.pa_string.syntax
  A language extension added the ability to declare and pattern-match against new kinds of strings.
batteries.pa_llist.syntax
  A language extension that makes it easier to pattern match against lazy lists.

For more information on how to use these packages, please see the documentation of findlib.