4

I was looking at the manual and found that there are attributes in OCaml for declaring things as deprecated (see http://caml.inria.fr/pub/docs/manual-ocaml/extn.html), but I can not figure out how to get them to be recognized by the compiler.

Here's the program that I wrote:

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

(I also tried [@@deprecated ...] rather than [@@ocaml.deprecated ...] with the same results). I don't get any warnings when I run:

ocamlbuild src/trial.byte

Is there something that I need to set up in my _tags file? Is there something else that I'm missing here?

objmagic
  • 1,028
  • 1
  • 9
  • 18
Gregory
  • 1,205
  • 10
  • 17
  • Seems like (1) `[@deprecated "don't use this"]` (with one `@`) after the type `t` definition works for me (tested with both OCaml 4.02.3 and 4.03.0); (2) neither `@deprecated` nor `@@deprecated` works after the `let x = 1` expression. There is a strange quirk also: `Warning 3: deprecated: Y don't use this` gets printed twice for the last line. – Anton Trunov May 04 '16 at 19:12

2 Answers2

3

The deprecated annotation is only available for values (not on types), and mostly in signatures. In your case, here how it should be done:

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
Drup
  • 3,679
  • 13
  • 14
  • Thanks, this is good to know. This suggests that there is a way to store (and access) annotations within a cmi file. Is that right? If so, is there a way to view them? – Gregory May 04 '16 at 22:34
  • I don't think there is a way to see them at the moment. This would be an excellent feature for ocp-index/browser! Could you propose it ? – Drup May 04 '16 at 22:59
1

Seems to work from 4.02.3, for this version, #require "ppx_jane";; before your code. With 4.03.0, it works natively.

Pierre G.
  • 4,346
  • 1
  • 12
  • 25