ocamlutop

@@deriving sexp is not working on utop


I'm running this code in utop:

# type u = { a: int; b: float } [@@deriving sexp];;

But the expected declarations of s-expression converters are not generated.

I have Core 0.11.0 and utop version 2.1.0 installed.

the version of Ocaml is 4.06.1.

Thanks.


Solution

  • You need to pass -require so that the ppx is loaded. In addition (that's specific to this driver), you need to pass its runtime in scope using -require sexplib and a manual open Sexplib.Std:

    % utop -require ppx_sexp_conv -require sexplib                  
    utop # open Sexplib.Std;;
    utop # type u = { a: int; b: float } [@@deriving sexp];;
    type u = { a : int; b : float; }
    val u_of_sexp : Sexplib0.Sexp.t -> u = <fun>
    val sexp_of_u : u -> Sexplib0.Sexp.t = <fun>