Sexplib

Sexplib is an automated code generation for converting OCaml-values to S-expressions for OCaml 3.10 and newer. Basically, it automatically provides functions for type-safe serialization and deserialization in S-expression format from type definitions.

Tips

 TYPE_CONV_PATH "Something"

to your files.

 let t_of_sexp key_of_sexp data_of_sexp = function
   | List l ->
       List.fold_left
         (fun map x ->
           let (k,v) = pair_of_sexp key_of_sexp data_of_sexp x in
           add k v map
         )
         empty
         l
   | Atom _ as sexp -> of_sexp_error "Xmap.t_of_sexp: list needed" sexp
 let sexp_of_t sexp_of_key sexp_of_data map =
   List(
     fold
       (fun k v result ->
         (sexp_of_pair sexp_of_key sexp_of_data (k,v)) :: result
       )
       map
       []
   )
type t = (int, (string * float) list) Hashtbl.t with sexp
 Printf.printf "My complex value of type foo for which I'm too lazy to write a proper printer is %a" Sexp.output_hum (sexp_of_foo x)

Links

Site: http://www.ocaml.info/home/ocaml_sources.html Alternatives: json-wheel Ocamlrpc ioXML See: Serialization