module CCSexp:sig
..end
typet =
[ `Atom of string | `List of t list ]
val equal : t -> t -> bool
val compare : t -> t -> int
val hash : t -> int
val atom : string -> t
val of_int : int -> t
val of_bool : bool -> t
val of_list : t list -> t
val of_rev_list : t list -> t
val of_float : float -> t
val of_unit : t
val of_pair : t * t -> t
val of_triple : t * t * t -> t
val of_quad : t * t * t * t -> t
val of_variant : string -> t list -> t
of_variant name args
is used to encode algebraic variants
into a S-expr. For instance of_variant "some" [of_int 1]
represents the value Some 1
val of_field : string -> t -> t
val of_record : (string * t) list -> t
Example: serializing 2D points
type pt = {x:int; y:int };;
let pt_of_sexp e =
Sexp.Traverse.(
field "x" to_int e >>= fun x ->
field "y" to_int e >>= fun y ->
return {x;y}
);;
let sexp_of_pt pt = Sexp.(of_record ["x", of_int pt.x; "y", of_int pt.y]);;
let l = [{x=1;y=1}; {x=2;y=10}];;
let sexp = Sexp.(of_list (List.map sexp_of_pt l));;
Sexp.Traverse.list_all pt_of_sexp sexp;;
module Traverse:sig
..end