Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does annotating a type with sexp return cause Unbound value int_of_sexp?

Tags:

ocaml

camlp4

Using the sexplib syntax extension to automatically generate serialization code for a type, as shown in many simple examples online:

open Sexplib
type t = { foo : int; bar : string; } with sexp
let v = { foo = 3; bar = "baz"; } in
sexp_of_t v

Fails to compile, with Error: Unbound value int_of_sexp.

like image 841
jrk Avatar asked Jun 21 '12 17:06

jrk


1 Answers

In more recent versions of sexplib, you need to first open Sexplib.Std, which includes the standard type serialization routines in the namespace of the generated code.

So:

open Sexplib
open Sexplib.Std (* newly essential import *)
type t = { foo : int; bar : string; } with sexp
let v = { foo = 3; bar = "baz"; } in
sexp_of_t v

works.

like image 55
jrk Avatar answered Nov 10 '22 00:11

jrk