注释 – 如何在OCaml中注释让绑定弃用?
发布时间:2020-12-15 00:55:50 所属栏目:Java 来源:网络整理
导读:我想要将外部库中的函数注释为已弃用,以确保它不会在我的项目中使用.我们假设该库提供以下模块: module Lib : sig val safe_function : int - unit val unsafe_function : int - int - unitend = struct let safe_function _ = () let unsafe_function _ _
我想要将外部库中的函数注释为已弃用,以确保它不会在我的项目中使用.我们假设该库提供以下模块:
module Lib : sig val safe_function : int -> unit val unsafe_function : int -> int -> unit end = struct let safe_function _ = () let unsafe_function _ _ = () end 我的项目中有一个Util.ml文件,我在每个文件中打开.在其中,我想做类似的事情: open Lib let unsafe_function = Lib.unsafe_function [@@deprecated "Use safe_function instead."] let foo = (fun x -> x) [@@deprecated "BBB"] type t = | A [@deprecated] | B [@deprecated] [@@deprecated] 编译以下usage.ml文件 open Util let _ = unsafe_function 0 0 let _ = foo 0 let _ = A let f (x : t) = x 产生以下警告: $ocamlc -c -w +3 usage.ml File "usage.ml",line 6,characters 8-9: Warning 3: deprecated: A File "usage.ml",line 7,characters 11-12: Warning 3: deprecated: Util.t 因此,let-bindings上不推荐使用的属性不会触发,但类型定义和构造函数上的属性会触发. attribute syntax似乎允许两者. 我找到了this answer,但似乎已经过时,因为: >它明确地说它“仅适用于值(不适用于类型)”,这不是真的(不再是?),如上例所示. 解决方法
我不确定具体的语法是什么(你的建议听起来正确并且对应于解析器代码,所以它可能是编译器中的一个错误),但你可以(ab)使用模块系统来做到这一点:
include (Lib : sig val unsafe_function : int -> int -> unit [@@ocaml.deprecated "Use safe_function instead."] end) let _ = unsafe_function 0 0 (* warning here *) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |