使用 ppx_deriving 打印抽象语法树
Printing abstract syntax tree using ppx_deriving
有人能告诉我为什么这段代码不能编译吗?我正在尝试使用 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
添加 -use-ocamlfind
作为 ocamlbuild 的第一个参数。它应该可以解决问题。
(您在 [Incv, Incv]
中也有错别字,,
应该是 ;
。
有人能告诉我为什么这段代码不能编译吗?我正在尝试使用 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
添加 -use-ocamlfind
作为 ocamlbuild 的第一个参数。它应该可以解决问题。
(您在 [Incv, Incv]
中也有错别字,,
应该是 ;
。