Search code examples
ocamlocamlfind

OCaml compile error with ocamlfind


Here is the code:

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

Here is the _tags

true: syntax(camlp4o)
true: package(deriving,deriving.syntax)
true: thread,debug,annot
true: bin_annot

Here is the compile command:

ocamlbuild -use-ocamlfind test.native

Here is the compile error:

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.

However, when I use this:

ocamlbuild test.native

Then the code can be successfully compiled...


Solution

  • This is because ocamlbuild -use-ocamlfind test.native directs compiler to use camlp4 parser. It is a bit different from standard OCaml parser. Actually, parser is a keyword in camlp4, so you can't use it as a class name. Just rename it.