2014-04-24 258 views
0

下面是代碼:OCaml的編譯錯誤與ocamlfind

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 

然後代碼可以編譯成功...

回答

1

這是因爲ocamlbuild -use-ocamlfind test.native指示編譯器使用camlp4解析器。它與標準OCaml解析器有點不同。實際上,parser是camlp4中的一個關鍵字,因此您不能將其用作類名稱。只需重命名它。

+0

是的,我沒有想到過這樣的錯誤,謝謝! – computereasy