如何设置ocamlinit以便ppx有效?

时间:2016-12-27 23:37:40

标签: ocaml utop ppx

这是我的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;;

准确地说,我在utop中得到了这个

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

如果我使用以#ppx开头的行代替#require "ppx_jane",我会收到此错误

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

我应该如何设置ocamlinit以使用[@@deriving show]

2 个答案:

答案 0 :(得分:1)

我设法让它使用#require "ppx_deriving.show";;(有或没有#require "ppx_jane";;)。

答案 1 :(得分:0)

除了皮埃尔的建议,我发现我需要 ppx_jane行。

另外,我使用#require "ppx_deriving.std"代替ppx_deriving.show来获取ord以及其他内容。

这是我完整的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;;