我查看了手册,发现在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文件中有什么需要设置的吗?这里还有什么东西我遗漏了吗?
发布于 2016-05-04 21:52:50
不推荐的注释仅适用于值(不适用于类型),而且主要用于签名。就您的情况而言,在这里应该如何做:
module M : sig
val x : int [@@deprecated "don't use this"]
type t =
| X [@deprecated "don't use this"]
| Y [@deprecated "don't use this"]
end = struct
let x = 1
type t = X | Y
end
open M
let _ =
let y = Y in
match y with
| X ->
print_string (string_of_int x)
| Y -> assert false发布于 2016-05-04 18:36:10
似乎是从4.02.3开始工作的,对于这个版本,在您的代码之前使用#require "ppx_jane";;。使用4.03.0,它可以本地工作。
https://stackoverflow.com/questions/37035225
复制相似问题