How to annotate binding as deprecated in OCaml?

I want to annotate a function from an external library as deprecated to make sure that it will not be used in my project. Suppose the library offers the following module:

module Lib : sig
  val safe_function : int -> unit
  val unsafe_function : int -> int -> unit
end = struct
  let safe_function _ = ()
  let unsafe_function _ _ = ()
end

I have a file Util.mlin my project that I open in every file. In this, I would like to do something like this:

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]

Compiling the following file usage.ml

open Util

let _ = unsafe_function 0 0
let _ = foo 0

let _ = A
let f (x : t) = x

issues the following warnings:

$ 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

Thus, attributes deprecatedin let-bindings are not triggered, but those that are contained in the type definition and constructors. The attribute syntax seems to allow both.

I found this answer , but it is deprecated because:

  • , " ( )" , (?), .
  • , " ."
+6
1

, ( , ​​), (ab) :

include (Lib : sig
    val unsafe_function : int -> int -> unit
    [@@ocaml.deprecated "Use safe_function instead."]
  end)

let _ = unsafe_function 0 0 (* warning here *)
+3

All Articles