(* The wire format Serializers and deserializers for basic datatypes Generic, typed serialization and de-serialization based on type representations *) (* The wire format: essentially JSON *) type wire_atom = | UInt of int | UStr of string type wire_t = WAtom of wire_atom | WComp of wire_t list val show_wire : wire_t -> string type 'a partial = Err of string | Datum of 'a type 'a to_wire = 'a -> wire_t type 'a from_wire = wire_t -> 'a partial (* Serializers and de-serializers for a few standard types *) val unit_to_wire : unit to_wire val unit_from_wire : unit from_wire val int_to_wire : int to_wire val int_from_wire : int from_wire val bool_to_wire : bool to_wire val bool_from_wire : bool from_wire val string_to_wire : string to_wire val string_from_wire : string from_wire val tup2_to_wire : 'a to_wire -> 'b to_wire -> ('a * 'b) to_wire val tup2_from_wire : 'a from_wire -> 'b from_wire -> ('a * 'b) from_wire (* Convenient wrappers for for a few popular function types *) val fn_int_int : (int -> int) -> (wire_t -> wire_t) val fn_int2_bool : (int * int -> bool) -> (wire_t -> wire_t) val fn_intint_bool : (int -> int -> bool) -> (wire_t -> wire_t -> wire_t) (* Type representation *) type 'a typerep (* abstract *) val unit_typerep : unit typerep val int_typerep : int typerep val bool_typerep : bool typerep val string_typerep : string typerep val tup2_typerep : 'a typerep -> 'b typerep -> ('a * 'b) typerep val arr_typerep : 'a typerep -> 'b typerep -> ('a -> 'b) typerep val arrow_result : ('a->'b) typerep -> 'b typerep (* Embedding-projection between a user-defined datatype 'a and another type 'b, typically a sum-of-products view *) type ('a,'b) iso = {iso_ab : 'a -> 'b; iso_ba : 'b -> 'a partial} val user_typerep : ('a,'b) iso -> 'b typerep -> 'a typerep (* Generic, typed serialization and de-serialization *) val gen_to_wire : 'a typerep -> 'a to_wire val gen_from_wire : 'a typerep -> 'a from_wire