04.06.09

OCaml Batteries Included Beta 1

Publié dans In English / En anglais, Informatique / Computer science, OCaml, Recherche / Research, batteries included tagged , , , , , , , , , , à 10:24 par yoric

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\n";;
val format : (string -> 'a, 'a) Batteries.Print.format =
  {Batteries.Print.pattern = "Let's print a string:%(0)\n";
   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}\n" [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.

9 commentaires »

  1. Alp a dit,

    Great work, cheers !

  2. Paolo Donadeo a dit,

    Two notes: first, this library is a dream and it’s just the beginning! Thanks a lot to all those are working hard on this project.

    Second, about your initial note. I’m very sad to see that also in France researchers are considered “improductive”, it’s an old movie here in Italy.

    FWTW, I’m with you all.

  3. Snark a dit,

    All of this is pretty exciting — the talk in Grenoble already whet my appetite.

    Not sure the baccalauréat will be affected : theoretically, it should ; practically it’s such a joke already…

    • yoric a dit,

      All of this is pretty exciting

      Thanks.

      Not sure the baccalauréat will be affected : theoretically, it should ; practically it’s such a joke already…

      Sure. But we can stop being accomplices to that joke.

  4. [...] Batteries Included — OCaml Batteries Included Beta 1 is out ! If you still don’t know about it, you should quickly go on its website on OCamlCore, download [...]

  5. [...] Pour finir, quelques liens : Site officiel Documentation de l’API Documentation de la plateforme Billet de blog sur la publication de la Beta 1 [...]

  6. Sorry, but do you know more about the GODI package? As far as I can see from their Web site, they are still at 0.20090206godi6, which I assume is the Alpha 3 release.

    As a newbie, GODI was the perfect way to install Batteries (alpha); I’d love to take the Beta for a spin, but had trouble building it from source.

    • yoric a dit,

      As far as I can see from their Web site, they are still at 0.20090206godi6, which I assume is the Alpha 3 release.

      The GODI package for OCaml 3.11 is available from godi_console.
      Officially, it’s also available for OCaml 3.10, but we have just found a bug which prevents from compiling the 3.10 version.

  7. Ah, thank you! That worked like a charm; I should have thought to “just try”.

    Congratulations on the beta release, I think these are very exciting times for Ocaml thanks to the Batteries project.


Laisser un commentaire