How do I setup ocamlinit so that ppx works?

859 views Asked by At

This is my ocamlinit:

(* Added by OPAM. *)
let () =
  try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
  with Not_found -> ()
;;

(* ## added by OPAM user-setup for ocamltop / base ## 3ec62baf6f9c219ae06d9814069da862 ## you can edit, but keep this line *)

#use "topfind";;
(* ## end of OPAM user-setup addition for ocamltop / base ## keep this line *)

#thread;;

(* #ppx "ppx-jane -as-ppx";; *)
#require "ppx_jane";;
#require "core.top";;
#require "async";;
#require "core_extended";;


open Core.Std;;

With this exactly, I get this in utop

utop # type test = char list [@@deriving show];;
Error: Cannot locate deriver show 

If I use the line beginning with #ppx instead of #require "ppx_jane", I get this error

utop # type test = char list [@@deriving show];;
Error: ppx_type_conv: 'show' is not a supported type type-conv generator

How should I set up ocamlinit to use [@@deriving show]?

2

There are 2 answers

1
Pierre G. On

I managed to have it working using #require "ppx_deriving.show";; (with or without #require "ppx_jane";;).

3
ackerleytng On

In addition to Pierre's suggestion, I found that I needed the line with ppx_jane.

Also, I used #require "ppx_deriving.std" instead of just ppx_deriving.show to get ord and the rest of the stuff too.

Here's my full ocamlinit

(* Added by OPAM. *)
let () =
  try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
  with Not_found -> ()
;;

(* ## added by OPAM user-setup for ocamltop / base ## 3ec62baf6f9c219ae06d9814069da862 ## you can edit, but keep this line *)
#use "topfind";;
(* ## end of OPAM user-setup addition for ocamltop / base ## keep this line *)

#thread;;

#require "ppx_jane";;
#require "core.top";;
#require "async";;
#require "core_extended";;

#require "ppx_deriving.std";;

open Core.Std;;