以下是代码:
class parser =
let test1 = function
| 1 -> print_int 1
| 2 -> print_int 2
| _ -> print_int 3 in
let test = function
| 1 -> print_int 1
| 2 -> print_int 2
| _ -> print_int 3 in
object(self)
end
以下是_tags
true: syntax(camlp4o)
true: package(deriving,deriving.syntax)
true: thread,debug,annot
true: bin_annot
这是编译命令:
ocamlbuild -use-ocamlfind test.native
这是编译错误:
Warning: tag "package" does not expect a parameter, but is used with parameter "deriving,deriving.syntax"
Warning: tag "syntax" does not expect a parameter, but is used with parameter "camlp4o"
+ /usr/local/bin/ocamldep.opt -modules test.ml > test.ml.depends
File "test.ml", line 8, characters 0-3:
Error: Syntax error
Command exited with code 2.
Compilation unsuccessful after building 1 target (0 cached) in 00:00:00.
然而,当我使用它时:
ocamlbuild test.native
然后代码可以成功编译......
答案 0 :(得分:1)
这是因为ocamlbuild -use-ocamlfind test.native
指示编译器使用camlp4解析器。它与标准OCaml解析器略有不同。实际上,parser
是camlp4中的关键字,因此您无法将其用作类名。只需重命名即可。