Module Sexplib.Conv
include module type of Sexplib0.Sexp_conv
type 'a sexp_option
= 'a option
type 'a sexp_list
= 'a list
type 'a sexp_array
= 'a array
type 'a sexp_opaque
= 'a
Conversion of OCaml-values to S-expressions
val default_string_of_float : (float -> string) Stdlib.ref
default_string_of_float
reference to the default function used to convert floats to strings.Initially set to
fun n -> sprintf "%.20G" n
.
val write_old_option_format : bool Stdlib.ref
write_old_option_format
reference for the default option format used to write option values. If set totrue
, the old-style option format will be used, the new-style one otherwise.Initially set to
true
.
val read_old_option_format : bool Stdlib.ref
read_old_option_format
reference for the default option format used to read option values.Of_sexp_error
will be raised with old-style option values if this reference is set tofalse
. Reading new-style option values is always supported. Using a global reference instead of changing the converter calling conventions is the only way to avoid breaking old code with the standard macros.Initially set to
true
.
val list_map : ('a -> 'b) -> 'a list -> 'b list
We re-export a tail recursive map function, because some modules override the standard library functions (e.g.
StdLabels
) which wrecks havoc with the camlp4 extension.
val sexp_of_unit : unit -> Sexplib0.Sexp.t
sexp_of_unit ()
converts a value of typeunit
to an S-expression.
val sexp_of_bool : bool -> Sexplib0.Sexp.t
sexp_of_bool b
converts the valuex
of typebool
to an S-expression.
val sexp_of_string : string -> Sexplib0.Sexp.t
sexp_of_bool str
converts the valuestr
of typestring
to an S-expression.
val sexp_of_bytes : bytes -> Sexplib0.Sexp.t
sexp_of_bool str
converts the valuestr
of typebytes
to an S-expression.
val sexp_of_char : char -> Sexplib0.Sexp.t
sexp_of_char c
converts the valuec
of typechar
to an S-expression.
val sexp_of_int : int -> Sexplib0.Sexp.t
sexp_of_int n
converts the valuen
of typeint
to an S-expression.
val sexp_of_float : float -> Sexplib0.Sexp.t
sexp_of_float n
converts the valuen
of typefloat
to an S-expression.
val sexp_of_int32 : int32 -> Sexplib0.Sexp.t
sexp_of_int32 n
converts the valuen
of typeint32
to an S-expression.
val sexp_of_int64 : int64 -> Sexplib0.Sexp.t
sexp_of_int64 n
converts the valuen
of typeint64
to an S-expression.
val sexp_of_nativeint : nativeint -> Sexplib0.Sexp.t
sexp_of_nativeint n
converts the valuen
of typenativeint
to an S-expression.
val sexp_of_ref : ('a -> Sexplib0.Sexp.t) -> 'a Stdlib.ref -> Sexplib0.Sexp.t
sexp_of_ref conv r
converts the valuer
of type'a ref
to an S-expression. Usesconv
to convert values of type'a
to an S-expression.
val sexp_of_lazy_t : ('a -> Sexplib0.Sexp.t) -> 'a lazy_t -> Sexplib0.Sexp.t
sexp_of_lazy_t conv l
converts the valuel
of type'a lazy_t
to an S-expression. Usesconv
to convert values of type'a
to an S-expression.
val sexp_of_option : ('a -> Sexplib0.Sexp.t) -> 'a option -> Sexplib0.Sexp.t
sexp_of_option conv opt
converts the valueopt
of type'a option
to an S-expression. Usesconv
to convert values of type'a
to an S-expression.
val sexp_of_pair : ('a -> Sexplib0.Sexp.t) -> ('b -> Sexplib0.Sexp.t) -> ('a * 'b) -> Sexplib0.Sexp.t
sexp_of_pair conv1 conv2 pair
converts a pair to an S-expression. It uses its first argument to convert the first element of the pair, and its second argument to convert the second element of the pair.
val sexp_of_triple : ('a -> Sexplib0.Sexp.t) -> ('b -> Sexplib0.Sexp.t) -> ('c -> Sexplib0.Sexp.t) -> ('a * 'b * 'c) -> Sexplib0.Sexp.t
sexp_of_triple conv1 conv2 conv3 triple
converts a triple to an S-expression usingconv1
,conv2
, andconv3
to convert its elements.
val sexp_of_list : ('a -> Sexplib0.Sexp.t) -> 'a list -> Sexplib0.Sexp.t
sexp_of_list conv lst
converts the valuelst
of type'a list
to an S-expression. Usesconv
to convert values of type'a
to an S-expression.
val sexp_of_array : ('a -> Sexplib0.Sexp.t) -> 'a array -> Sexplib0.Sexp.t
sexp_of_array conv ar
converts the valuear
of type'a array
to an S-expression. Usesconv
to convert values of type'a
to an S-expression.
val sexp_of_hashtbl : ('a -> Sexplib0.Sexp.t) -> ('b -> Sexplib0.Sexp.t) -> ('a, 'b) Stdlib.Hashtbl.t -> Sexplib0.Sexp.t
sexp_of_hashtbl conv_key conv_value htbl
converts the valuehtbl
of type('a, 'b) Hashtbl.t
to an S-expression. Usesconv_key
to convert the hashtable keys of type'a
, andconv_value
to convert hashtable values of type'b
to S-expressions.
val sexp_of_opaque : 'a -> Sexplib0.Sexp.t
sexp_of_opaque x
converts the valuex
of opaque type to an S-expression. This means the user need not provide converters, but the result cannot be interpreted.
val sexp_of_fun : ('a -> 'b) -> Sexplib0.Sexp.t
sexp_of_fun f
converts the valuef
of function type to a dummy S-expression. Functions cannot be serialized as S-expressions, but at least a placeholder can be generated for pretty-printing.
Conversion of S-expressions to OCaml-values
exception
Of_sexp_error of exn * Sexplib0.Sexp.t
Of_sexp_error (exn, sexp)
the exception raised when an S-expression could not be successfully converted to an OCaml-value.
val record_check_extra_fields : bool Stdlib.ref
record_check_extra_fields
checks for extra (= unknown) fields in record S-expressions.
val of_sexp_error : string -> Sexplib0.Sexp.t -> 'a
of_sexp_error reason sexp
- raises Of_sexp_error
(Failure reason, sexp).
val of_sexp_error_exn : exn -> Sexplib0.Sexp.t -> 'a
of_sexp_error exc sexp
- raises Of_sexp_error
(exc, sexp).
val unit_of_sexp : Sexplib0.Sexp.t -> unit
unit_of_sexp sexp
converts S-expressionsexp
to a value of typeunit
.
val bool_of_sexp : Sexplib0.Sexp.t -> bool
bool_of_sexp sexp
converts S-expressionsexp
to a value of typebool
.
val string_of_sexp : Sexplib0.Sexp.t -> string
string_of_sexp sexp
converts S-expressionsexp
to a value of typestring
.
val bytes_of_sexp : Sexplib0.Sexp.t -> bytes
bytes_of_sexp sexp
converts S-expressionsexp
to a value of typebytes
.
val char_of_sexp : Sexplib0.Sexp.t -> char
char_of_sexp sexp
converts S-expressionsexp
to a value of typechar
.
val int_of_sexp : Sexplib0.Sexp.t -> int
int_of_sexp sexp
converts S-expressionsexp
to a value of typeint
.
val float_of_sexp : Sexplib0.Sexp.t -> float
float_of_sexp sexp
converts S-expressionsexp
to a value of typefloat
.
val int32_of_sexp : Sexplib0.Sexp.t -> int32
int32_of_sexp sexp
converts S-expressionsexp
to a value of typeint32
.
val int64_of_sexp : Sexplib0.Sexp.t -> int64
int64_of_sexp sexp
converts S-expressionsexp
to a value of typeint64
.
val nativeint_of_sexp : Sexplib0.Sexp.t -> nativeint
nativeint_of_sexp sexp
converts S-expressionsexp
to a value of typenativeint
.
val ref_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a Stdlib.ref
ref_of_sexp conv sexp
converts S-expressionsexp
to a value of type'a ref
using conversion functionconv
, which converts an S-expression to a value of type'a
.
val lazy_t_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a lazy_t
lazy_t_of_sexp conv sexp
converts S-expressionsexp
to a value of type'a lazy_t
using conversion functionconv
, which converts an S-expression to a value of type'a
.
val option_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a option
option_of_sexp conv sexp
converts S-expressionsexp
to a value of type'a option
using conversion functionconv
, which converts an S-expression to a value of type'a
.
val pair_of_sexp : (Sexplib0.Sexp.t -> 'a) -> (Sexplib0.Sexp.t -> 'b) -> Sexplib0.Sexp.t -> 'a * 'b
pair_of_sexp conv1 conv2 sexp
converts S-expressionsexp
to a pair of type'a * 'b
using conversion functionsconv1
andconv2
, which convert S-expressions to values of type'a
and'b
respectively.
val triple_of_sexp : (Sexplib0.Sexp.t -> 'a) -> (Sexplib0.Sexp.t -> 'b) -> (Sexplib0.Sexp.t -> 'c) -> Sexplib0.Sexp.t -> 'a * 'b * 'c
triple_of_sexp conv1 conv2 conv3 sexp
converts S-expressionsexp
to a triple of type'a * 'b * 'c
using conversion functionsconv1
,conv2
, andconv3
, which convert S-expressions to values of type'a
,'b
, and'c
respectively.
val list_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a list
list_of_sexp conv sexp
converts S-expressionsexp
to a value of type'a list
using conversion functionconv
, which converts an S-expression to a value of type'a
.
val array_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a array
array_of_sexp conv sexp
converts S-expressionsexp
to a value of type'a array
using conversion functionconv
, which converts an S-expression to a value of type'a
.
val hashtbl_of_sexp : (Sexplib0.Sexp.t -> 'a) -> (Sexplib0.Sexp.t -> 'b) -> Sexplib0.Sexp.t -> ('a, 'b) Stdlib.Hashtbl.t
hashtbl_of_sexp conv_key conv_value sexp
converts S-expressionsexp
to a value of type('a, 'b) Hashtbl.t
using conversion functionconv_key
, which converts an S-expression to hashtable key of type'a
, and functionconv_value
, which converts an S-expression to hashtable value of type'b
.
val opaque_of_sexp : Sexplib0.Sexp.t -> 'a
opaque_of_sexp sexp
- raises Of_sexp_error
when attempting to convert an S-expression to an opaque value.
val fun_of_sexp : Sexplib0.Sexp.t -> 'a
fun_of_sexp sexp
- raises Of_sexp_error
when attempting to convert an S-expression to a function.
val sexp_of_exn : exn -> Sexplib0.Sexp.t
sexp_of_exn exc
converts exceptionexc
to an S-expression. If no suitable converter is found, the standard converter inPrintexc
will be used to generate an atomic S-expression.
val sexp_of_exn_opt : exn -> Sexplib0.Sexp.t option
sexp_of_exn_opt exc
converts exceptionexc
toSome sexp
. If no suitable converter is found,None
is returned instead.
module Exn_converter = Sexplib0.Sexp_conv.Exn_converter
Type aliases
type bigstring
= (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
type float32_vec
= (float, Bigarray.float32_elt, Bigarray.fortran_layout) Bigarray.Array1.t
type float64_vec
= (float, Bigarray.float64_elt, Bigarray.fortran_layout) Bigarray.Array1.t
type vec
= float64_vec
type float32_mat
= (float, Bigarray.float32_elt, Bigarray.fortran_layout) Bigarray.Array2.t
type float64_mat
= (float, Bigarray.float64_elt, Bigarray.fortran_layout) Bigarray.Array2.t
type mat
= float64_mat
Conversion of OCaml-values to S-expressions
val sexp_of_bigstring : bigstring -> Sexp.t
sexp_of_bigstring bstr
converts a bigstring (character bigarray in C-layout) to an S-expression.
val sexp_of_float32_vec : float32_vec -> Sexp.t
sexp_of_float32_vec vec
converts the one-dimensional bigarrayvec
of 32-bit floats in Fortran-layout to an S-expression.
val sexp_of_float64_vec : float64_vec -> Sexp.t
sexp_of_float64_vec vec
converts the one-dimensional bigarrayvec
of 64-bit floats in Fortran-layout to an S-expression.
val sexp_of_vec : vec -> Sexp.t
sexp_of_vec vec
same asConv.sexp_of_float64_vec
.
val sexp_of_float32_mat : float32_mat -> Sexp.t
sexp_of_float32_mat mat
converts the two-dimensional bigarraymat
of 32-bit floats in Fortran-layout to an S-expression.
val sexp_of_float64_mat : float64_mat -> Sexp.t
sexp_of_float64_mat mat
converts the two-dimensional bigarraymat
of 64-bit floats in Fortran-layout to an S-expression.
val sexp_of_mat : mat -> Sexp.t
sexp_of_mat mat
same asConv.sexp_of_float64_mat
.
val string_of__of__sexp_of : ('a -> Sexp.t) -> 'a -> string
string_of__of__sexp_of conv x
converts the OCaml-valuex
to an S-expression represented as a string by using conversion functionconv
.
Conversion of S-expressions to OCaml-values
val bigstring_of_sexp : Sexp.t -> bigstring
bigstring_of_sexp sexp
converts S-expressionsexp
to a bigstring (character bigarray in C-layout).
val float32_vec_of_sexp : Sexp.t -> float32_vec
float32_vec_of_sexp sexp
converts S-expressionsexp
to a one-dimensional bigarray of 32-bit floats in Fortran-layout.
val float64_vec_of_sexp : Sexp.t -> float64_vec
float64_vec_of_sexp sexp
converts S-expressionsexp
to a one-dimensional bigarray of 64-bit floats in Fortran-layout.
val vec_of_sexp : Sexp.t -> vec
vec_of_sexp sexp
same asfloat64_vec_of_sexp
.
val float32_mat_of_sexp : Sexp.t -> float32_mat
float32_mat_of_sexp sexp
converts S-expressionsexp
to a two-dimensional bigarray of 32-bit floats in Fortran-layout.
val float64_mat_of_sexp : Sexp.t -> float64_mat
float64_mat_of_sexp sexp
converts S-expressionsexp
to a two-dimensional bigarray of 64-bit floats in Fortran-layout.
val mat_of_sexp : Sexp.t -> mat
mat_of_sexp sexp
same asConv.float64_mat_of_sexp
.
val of_string__of__of_sexp : (Sexp.t -> 'a) -> string -> 'a
of_string__of__of_sexp conv str
converts the S-expressionstr
represented as a string to an OCaml-value by using conversion functionconv
.