Sexp.Sexp_maybeIf sexp_of_t fails, it returns Error rather than raising. You can convert values of this type to and from sexp in processes that can or cannot parse the underlying sexp in any combination and still recover the original value. Also, the Error case contains a human-readable description of the error.
A common use case is to parse most of a sexp even when some small part fails to parse, e.g.:
type query =
| Start of Initial_config.t Sexp_maybe.t
| Stop of Reason_to_stop.t Sexp_maybe.t
[@@deriving sexp]If Reason_to_stop.t_of_sexp fails, you can still tell it was a Stop query.
type 'a t = ('a, Base.Sexp.t * Error.t) Result.tinclude Bin_prot.Binable.S1 with type 'a t := 'a tval bin_shape_t : Bin_prot.Shape.t -> Bin_prot.Shape.tval bin_size_t : ('a, 'a t) Bin_prot.Size.sizer1val bin_write_t : ('a, 'a t) Bin_prot.Write.writer1val bin_read_t : ('a, 'a t) Bin_prot.Read.reader1val __bin_read_t__ : ('a, int -> 'a t) Bin_prot.Read.reader1val bin_writer_t : ('a, 'a t) Bin_prot.Type_class.S1.writerval bin_reader_t : ('a, 'a t) Bin_prot.Type_class.S1.readerval bin_t : ('a, 'a t) Bin_prot.Type_class.S1.tval compare : ('a -> 'a -> Base.Int.t) -> 'a t -> 'a t -> Base.Int.tval hash_fold_t : (Base.Hash.state -> 'a -> Base.Hash.state) -> Base.Hash.state -> 'a t -> Base.Hash.stateinclude Ppx_sexp_conv_lib.Sexpable.S1 with type 'a t := 'a tval t_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a tval sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t