首页 > 解决方案 > 使用 ocaml 属性引发用户定义的编译器警告

问题描述

有没有办法将属性附加到函数定义,以便编译器发出用户定义的警告消息,类似于 [@@deprecated] 所做的。

我想写一些类似的东西

let dangerous_function[@@warn "use this function with caution, are sure ?"] = ...

然后,编译代码

let _ = dangerous_function ...

会发出警告。

标签: ocaml

解决方案


目前这是不可能的,但这可能会成为OCaml 4.08 中的新功能

val foo: int -> int
    [@@ocaml.alert unsafe "Please use bar instead!"]

推荐阅读