type t = { foo: int; bar: float } [@@deriving sexp] ;;
type t = { foo : int; bar : float; }
val t_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> t = <fun>
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t = <fun>
t_of_sexp (Sexp.of_string "((bar 35) (foo 3))") ;;
- : t = {foo = 3; bar = 35.}
I tried
# type t = { foo: int; bar: float } [@@deriving sexp] ;;
type t = { foo : Base.int; bar : Base.float; }
# t_of_sexp (Sexp.of_string "((bar 35) (foo 3))");;
Error: Unbound value t_of_sexp
Hint: Did you mean mat_of_sexp or int_of_sexp?
By default, the compiler ignores annotations it doesn’t understand. (though once you turn on ppx_jane, you’ll get an error message for an unknown annotation.)
You are right, there will an error if I just type:
#require "ppx_jane";;
# type person = {name: string}[@@deriving bin_io];;
Error: Unbound value bin_shape_string
In order to make it works ,I have to search bin_prot’s github repo, and find some hints there:
##require "bin_prot";;
# open Bin_prot.Std;;
# type person = {name: string}[@@deriving bin_io];;
Characters 0-47:
Warning 3: deprecated: module Base.Pervasives
[2016-09] this element comes from the stdlib distributed with OCaml.
Refering to the stdlib directly is discouraged by Base. You should either
use the equivalent functionality offered by Base, or if you really want to
refer to the stdlib, use Caml.Pervasives instead
type person = { name : string; }
val bin_shape_person : Bin_prot.Shape.t = <abstr>
val bin_size_person : person -> int = <fun>
val bin_write_person : Bin_prot.Common.buf -> pos:int -> person -> int = <fun>
val bin_writer_person : person Bin_prot.Type_class.writer0 =
{Bin_prot.Type_class.size = <fun>; write = <fun>}
val bin_read_person :
Bin_prot.Common.buf -> pos_ref:Bin_prot.Common.pos_ref -> person = <fun>
val bin_reader_person : person Bin_prot.Type_class.reader0 =
{Bin_prot.Type_class.read = <fun>; vtag_read = <fun>}
val bin_person : person Bin_prot.Type_class.t0 =
{Bin_prot.Type_class.shape = <abstr>;
writer = {Bin_prot.Type_class.size = <fun>; write = <fun>};
reader = {Bin_prot.Type_class.read = <fun>; vtag_read = <fun>}}
If you open Core_kernel, bin_io will work more smoothly. Base has built-in support for s-expression conversion, but not bin_io. Core_kernel supports both.
It looks like you’re missing sexplib, which you can get by writing #require “sexplib”. But that shouldn’t be necessary, and I don’t see this issue on my setup, so I’m a little confused.