ocamls-expression

Unbound value "string_of_sexp"


It works quite well in utop with #require "ppx_jane" but I added (preprocess (pps ppx_jane)) in my dune file which looks like this:

(library
 (preprocess (pps ppx_jane))
 (name raftml)
 (modules raft rpc types)
 (libraries 
   core 
   core_unix 
   proto 
   grpc 
   grpc-lwt 
   ocaml-protoc 
   lwt 
   lwt.unix 
   h2 
   h2-lwt-unix 
   domainslib
   yojson
   ppx_jane
   ppx_sexp_conv
   ppx_deriving_yojson
   ppx_deriving
   ppx_deriving_yojson.runtime))

And my types are like this:

type log = {
    mutable command: string;
    mutable term: int32;
    mutable index: int32
} [@@deriving sexp]

I call sexp_of_log in my code like this:

let persist () = Out_channel.write_all "file_name" ~data:(Sexp.to_string (sexp_of_log { command = "hello"; term = (10l); index = (24l); }))

And there's an error when I run dune build: Unbound value "string_of_sexp"


Solution

  • I solved this by adding:

    open Sexplib.Std
    

    At the top of the file that has the record types deriving sexp.