Hi,
Some weeks ago I asked in the list about solutions for the long-term
storage of values in Ocaml. I was looking for a solution that was
not quite as brittle as the Marshal module, while still maintaining
reasonable performance and being able to deal with Ocaml types in
all their glory (recursive structures, etc).
Thanks for all your replies -- I got plenty of ideas and found out
about new libraries I didn't know existed. After some experimenting,
I settled for Sexplib; the main reason being the syntax extension that
automatically takes care of writing the (de)serialising functions.
However, if your requirements are different, you may find that another
solution might be more suitable. Here's a brief summary of the main
options I looked into: (let me know if there are others!)
- S-expressions using Sexplib. It has the advantage of being
quite fast, compact, and still human-readable-ish (if you like
parentheses). Moreover, the Camlp4 syntax extension makes the
creation of (de)serialising functions as straightforward as
appending "with sexp" to type definitions.
- Config_file. A strong contender if proper human-readability
is a requirement (it is far more readable than Sexplib, for
example). As far as I can tell, you still need to manually
create the (de)serialising functions for complex types, though.
Also, my guess is that the slightly more complex syntax will
make it slower than Sexplib.
- JSON. Possibly close to Config_file in terms of effort and
speed. Has the same advantage of being very human-friendly,
and the additional advantage of having quickly become a popular
interchange format (you'll find libraries for almost any language
out there).
- XML. Though Ocamlduce makes XML easier to deal with, the
only advantage I see in XML is its ubiquity. The format is
verbose, not all that human-friendly, and you still need to
manually create the (de)serialising functions.
- XDR. Though I have fond memories of using XDR with C (in a
different life), I have no experience with it in Ocaml.
Though it should be very fast, you also need to manually
create the (de)serialising functions.
- The I/O combinator library by Berke Durak. Seems similar
to XDR in terms of effort required. Does it still not
support recursive structures? That is a common requirement.
Cheers,
Dario Teixeira
___________________________________________________________
Rise to the challenge for Sport Relief with Yahoo! For Good
http://uk.promotions.yahoo.com/forgood/