我在手册中发现OCaml有用于声明过时内容的属性(参见http://caml.inria.fr/pub/docs/manual-ocaml/extn.html),但我不知道如何让编译器识别它们。
这是我写的程序:
这是我写的程序:
let x = 1 [@@ocaml.deprecated "don't use this"]
type t = X | Y [@@ocaml.deprecated "don't use this"]
let _ =
let y = Y in
match y with
| X ->
print_string (string_of_int x)
| Y -> assert false
我还尝试使用[@@deprecated ...]
而不是[@@ocaml.deprecated ...]
,但结果相同。当我运行时没有收到任何警告:
ocamlbuild src/trial.byte
我需要在我的_tags
文件中设置什么吗?还有其他我遗漏的地方吗?
[@deprecated "don't use this"]
(只有一个@
)是有效的(在OCaml 4.02.3和4.03.0中测试过)。但是,无论是@deprecated
还是@@deprecated
都不适用于let x = 1
表达式。还有一个奇怪的问题:最后一行会打印两次“警告3:已弃用:Y don't use this”。 - Anton Trunov