使用ppx_deriving打印抽象语法树

5

请问为什么这段代码无法编译?我试图使用ppx_deriving库打印抽象语法树。

type prog = command list
[@@deriving show]
and command =
   | Incv | Decv
   | Incp | Decp
   | Input  | Output
   | Loop of command list
   [@@deriving show]

let _ = Format.printf "%s" (show_prog ([Incv, Incv]))

hello:brainfuckinter mukeshtiwari$ ocamlbuild -package ppx_deriving.std  ast.byte
+ /Users/mukeshtiwari/.opam/4.02.1/bin/ocamlc.opt -c -I /Users/mukeshtiwari/.opam/4.02.1/lib/ppx_deriving -o ast.cmo ast.ml
File "ast.ml", line 10, characters 28-37:
Error: Unbound value show_prog
Command exited with code 2.
Compilation unsuccessful after building 2 targets (1 cached) in 00:00:00.
hello:brainfuckinter mukeshtiwari$ ocaml
    OCaml version 4.02.1

你的程序中的show_prog是什么? - alifirat
@alifirat 我在 #ocaml 频道中被建议使用它来推导出类似 https://github.com/whitequark/ppx_deriving/blob/master/src_examples/print_test.ml 的类型 prog 的显示实例。 - keep_learning
1个回答

5
-use-ocamlfind作为ocamlbuild的第一个参数。这将解决问题。
[Incv,Incv]中还存在一个拼写错误,,应该改为;。)

谢谢。是的,当编译器向我发出警告时,我注意到了这一点。 - keep_learning

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接