Note This post is written on the 64th day of University strikes in France. During these 64 days, the government has rejected any negociation on the core reasons for the strike, has attempted to discredit the contestation (if I understand correctly, I am both « improductive » and a « mask-wearing commando ») and has used police intimidation and repression. The strike continues. Quite possibly, there will be no university exams this year and no baccalauréat. If repression continues increasing, no one can tell for sure what will happen. Nothing good, for sure.

After days and nights of coding, debugging and fighting over naming conventions, the OCaml Batteries Included team is proud to announce OCaml Batteries Included Beta 1. You can find the binaries here, read the API documentation, the platform documentation, the release notes and the ChangeLog or the list of individual commits. A GODI package and a Debian/testing package are also available.

So, what’s new in Beta 1?

API freeze

Firstly, from now on, barring trivial changes and bugfixes, the API should be stable. So it’s a good time to start testing it with your projects and submitting bug reports.

Command-line tools

OCaml Batteries Included already had a drop-in replacement for ocamlc and ocamlopt, to automatically open, load and link all the necessary libraries and/or syntax extensions. To invoke them, use

$ ocamlfind batteries/ocamlc foo.ml

or

$ ocamlfind batteries/ocamlopt foo.ml

They behave essentially as their counterparts in the INRIA distribution.

Ok, that’s not new. What’s new is that OCaml Batteries Included now also has a drop-in replacement for ocaml, ocamldep and ocamlbuild. To launch the toplevel, run

$ ocamlfind batteries/ocaml

or to use it as an interpreter

$ ocamlfind batteries/ocaml foo.ml

Similarly, you may now use the ocamlbuild replacement

$ ocamlfind batteries/ocamlbuild foo.byte

or

$ ocamlfind batteries/ocamlbuild foo.native

What does this mean? Well, essentially, it means that you don’t have to do any complex configuration to take advantage of OCaml Batteries Included. Just replace every use of ocaml/ocamlc/ocamlopt/ocamlbuild with the corresponding drop-in replacement.

Toplevel

Since Alpha 2, the OCaml Batteries Included toplevel gives access to the manual, using directive #man . With Beta 1, a new directive #browse appears. This directive lets you insepct the contents of a module, regardless of whether the documentation has been generated:

$ rlwrap ocamlfind batteries/ocaml Objective Caml version 3.11.0 _________________________________ | | | | [| + | | Batteries Included - | |_______|_|_______________________| __________________________________ | | | | | - Type '#help;;' | | + |] |_______________________|_|________| # #browse "List";; module List : sig type 'a t = 'a list type 'a enumerable = 'a t type 'a mappable = 'a t val length : 'a list -> int val hd : 'a list -> 'a val tl : 'a list -> 'a list val is_empty : 'a list -> bool (*...*) end

This directive is provided as a quick way of understanding complex and undocumented modules — say, Camlp4.

Printf replacement

OCaml has long provided a useful but awkward Printf module. A few versions ago, OCaml Batteries Included introduced a partial replacement for Printf, more extensible and more compsable. With OCaml Batteries Included Beta 1, we now have a complete replacement, which is both safer, lightweight and more extensible. Let’s take a look :

# let format = p"Let's print a string: %s

";; val format : (string -> 'a, 'a) Batteries.Print.format = {Batteries.Print.pattern = "Let's print a string:%(0)

"; Batteries.Print.printer = <fun>} # Print.printf format "some text";; Let's print a string: some text - : unit = ()

Up to this point, there’s not much difference with the usual Printf module. But the nice thing is that this is completely extensible. It can be used just as well to print, say, lists:

# Print.printf p"Here's a list of integers: %{int list}

" [1;2;3;4;5];; Here's a list of integers: [1; 2; 3; 4; 5] - : unit = ()

Of course, this works just as well with arrays, ropes, and, well, just about every single data structure, including your own. You can add new printing functions, overload printing locally, etc.

And more

The OCaml Batteries Included toplevel now supports a .ocamlinit file, which can take advantage of all the features of Batteries.

Previous versions of OCaml Batteries Included introduced syntactic construction open List include Labels to create a new local module List containing the code of List and that of Labels . Due to ambiguities, the syntax was changed to open List with Labels

UTF-8 literal strings are now validated at compile-time

Conversion between Latin-1 literal strings and UTF-8 is now performed at compile-time

Modules Digest, Scanf, Format, Lexing now compatible with Batteries I/O

New out-of-the-box modules StringSet, IntSet, StringMap, IntMap, etc.

New module Future.Logger

The interpreter may now be called as a library

Improvements to Random, Enum, Bigarray, String, String.Cap, Set, PSet, …

Speed improvements in LazyList, Rope, String

Test suite

Build improvements, including parallel build, better detection of default directories

Numerous bugfixes

etc.