caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] a question about annotations
@ 2015-11-17 11:51 Matej Kosik
  2015-11-17 12:11 ` Gabriel Scherer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Matej Kosik @ 2015-11-17 11:51 UTC (permalink / raw)
  To: caml users

Dear Ocaml users,

A few days ago there was a question about how to disable a specific warning in a specific location
and the answer was to use

	[@warning "-<num>"]

annotation.

I tried it myself.
By trial and error I was able to figure out how to use it with "function" and "match" constructs.

With this fragment:

	type raw_frame =
	| Known_location of bool * string * int * int * int
	| Unknown_location of bool (*is_raise*)

I would like to temporarily disable warning 37:

	"Warning 37: constructor Known_location is never used to build values.
	 (However, this constructor appears in patterns.)"

However, by trial and error, I failed to figure out where is the proper place to put the [@warning "-37"] annotation:

Is there some document that describes where annotations are supported
and what do they mean?

I have skimmed the Reference Manual, but unfortunatelly, I can't find any relevant information.
Where should I look?

Thanks in advance.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] a question about annotations
  2015-11-17 11:51 [Caml-list] a question about annotations Matej Kosik
@ 2015-11-17 12:11 ` Gabriel Scherer
  2015-11-17 12:20 ` octachron
  2015-11-17 12:21 ` Alain Frisch
  2 siblings, 0 replies; 4+ messages in thread
From: Gabriel Scherer @ 2015-11-17 12:11 UTC (permalink / raw)
  To: Matej Kosik; +Cc: caml users

[-- Attachment #1: Type: text/plain, Size: 2193 bytes --]

Usage analysis is global and therefore not attached to a particular program
point. Only localized warning can be disabled using @warning.

A first question is why you would want to disable this warning: it seems
indeed to be a valid thing to warn about. (If the constructor is exported
through the .mli, then no warning will be emitted.)

One valid case where one wants to silence the warning is if values of these
types are only built by a C program on the other side of an OCaml/C FFI.
Then a valid way to disable the warning is:

  let _ = function
   | Known_location (a, b, c, d, e) -> Kown_location (a, b, c, d ,e)
   | x -> x

It might make sense to have an attribute [@mark_used] (or something like
that) to silence the warning at the declaration site, but I don't think it
currently exists.

On Tue, Nov 17, 2015 at 12:51 PM, Matej Kosik <
5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote:

> Dear Ocaml users,
>
> A few days ago there was a question about how to disable a specific
> warning in a specific location
> and the answer was to use
>
>         [@warning "-<num>"]
>
> annotation.
>
> I tried it myself.
> By trial and error I was able to figure out how to use it with "function"
> and "match" constructs.
>
> With this fragment:
>
>         type raw_frame =
>         | Known_location of bool * string * int * int * int
>         | Unknown_location of bool (*is_raise*)
>
> I would like to temporarily disable warning 37:
>
>         "Warning 37: constructor Known_location is never used to build
> values.
>          (However, this constructor appears in patterns.)"
>
> However, by trial and error, I failed to figure out where is the proper
> place to put the [@warning "-37"] annotation:
>
> Is there some document that describes where annotations are supported
> and what do they mean?
>
> I have skimmed the Reference Manual, but unfortunatelly, I can't find any
> relevant information.
> Where should I look?
>
> Thanks in advance.
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 3149 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] a question about annotations
  2015-11-17 11:51 [Caml-list] a question about annotations Matej Kosik
  2015-11-17 12:11 ` Gabriel Scherer
@ 2015-11-17 12:20 ` octachron
  2015-11-17 12:21 ` Alain Frisch
  2 siblings, 0 replies; 4+ messages in thread
From: octachron @ 2015-11-17 12:20 UTC (permalink / raw)
  To: caml-list

Concerning the documentation, as often with the reference manual, the 
relevant section is in the language extension part:
http://caml.inria.fr/distrib/ocaml-4.02/ocaml-4.02-refman.html#sec241.

However, this section is slightly out of date in the released manual due 
to recent change in the placement of the attribute:
https://github.com/ocaml/ocaml/pull/152.

Le 11/17/15 13:51, Matej Kosik a écrit :
> Dear Ocaml users,
>
> A few days ago there was a question about how to disable a specific warning in a specific location
> and the answer was to use
>
> 	[@warning "-<num>"]
>
> annotation.
>
> I tried it myself.
> By trial and error I was able to figure out how to use it with "function" and "match" constructs.
>
> With this fragment:
>
> 	type raw_frame =
> 	| Known_location of bool * string * int * int * int
> 	| Unknown_location of bool (*is_raise*)
>
> I would like to temporarily disable warning 37:
>
> 	"Warning 37: constructor Known_location is never used to build values.
> 	 (However, this constructor appears in patterns.)"
>
> However, by trial and error, I failed to figure out where is the proper place to put the [@warning "-37"] annotation:
>
> Is there some document that describes where annotations are supported
> and what do they mean?
>
> I have skimmed the Reference Manual, but unfortunatelly, I can't find any relevant information.
> Where should I look?
>
> Thanks in advance.
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] a question about annotations
  2015-11-17 11:51 [Caml-list] a question about annotations Matej Kosik
  2015-11-17 12:11 ` Gabriel Scherer
  2015-11-17 12:20 ` octachron
@ 2015-11-17 12:21 ` Alain Frisch
  2 siblings, 0 replies; 4+ messages in thread
From: Alain Frisch @ 2015-11-17 12:21 UTC (permalink / raw)
  To: Matej Kosik, caml users

On 17/11/2015 12:51, Matej Kosik wrote:
> Dear Ocaml users,
>
> A few days ago there was a question about how to disable a specific warning in a specific location
> and the answer was to use
>
> 	[@warning "-<num>"]
>
> annotation.

There is also the "structure item"-level form:

[@@@warning "..."]

which changes warning settings (for the rest of the current structure).

"Unused warnings" depend on the warning settings active where the item 
is defined.


Alain

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-11-17 12:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17 11:51 [Caml-list] a question about annotations Matej Kosik
2015-11-17 12:11 ` Gabriel Scherer
2015-11-17 12:20 ` octachron
2015-11-17 12:21 ` Alain Frisch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).