caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] How to use ocaml.warning
@ 2019-07-26  2:14 Ian Zimmerman
  2019-07-26  4:37 ` Nicolás Ojeda Bär
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Zimmerman @ 2019-07-26  2:14 UTC (permalink / raw)
  To: Caml Mailinglist

Hello, I wonder how to use the ocaml.warning attribute described here:

https://caml.inria.fr/pub/docs/manual-ocaml-4.08/manual035.html#sec265

To describe my situation, I had a list l of int pairs which I could prove
non-empty and I wanted to extract the first two ints.  I wrote

  let (i, j) :: rest = l in ...

and of course I got warning 8.  So I got interested in ways to suppress
the warning, and I read about the attributes which are new to me and
made me curious :P  I tried to insert

  [@ocaml.warning "-8"]

at many points in the code -- before the "let", before and after the
equal sign, and before "in" -- but none of these ways got rid of the
warning.  I gave up and used List.hd.  But I am still curious about the
intended or correct usage of the attribute feature.

Thanks.

-- 
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
To reply privately _only_ on Usenet and on broken lists
which rewrite From, fetch the TXT record for no-use.mooo.com.

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

* Re: [Caml-list] How to use ocaml.warning
  2019-07-26  2:14 [Caml-list] How to use ocaml.warning Ian Zimmerman
@ 2019-07-26  4:37 ` Nicolás Ojeda Bär
  2019-07-26 15:52   ` Ian Zimmerman
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolás Ojeda Bär @ 2019-07-26  4:37 UTC (permalink / raw)
  To: Ian Zimmerman; +Cc: Caml Mailinglist

Hello Ian,

In this case, you would want to attach the warning to the "let" binding:

    let[@warning "-8"] (i, j) :: rest = l in ...

Equivalently, you can use a postfix form:

    let (i, j) :: rest = l [@@warning "-8"] in ...

You can also attach the attribute to the whole "let" expression:

    (let (i, j) :: rest = l in ...) [@warning "-8"]

In this case, the warning is also disabled in the body of the "let" expression.

Going one step further, you can disable the warning on a whole section
of a file by using a "floating" form of the attribute:

    [@@@warning "-8"]
    ...

In this case, the warning will be disabled for any item appearing
after the attribute.

Having said this, I don't think disabling warning 8 is a good idea at all :)

Hope that helps!

Cheers,
--
Nicolás OJEDA BÄR
nicolas.ojeda.bar@lexifi.com
https://www.lexifi.com

On Fri, Jul 26, 2019 at 4:14 AM Ian Zimmerman <itz@very.loosely.org> wrote:
>
> Hello, I wonder how to use the ocaml.warning attribute described here:
>
> https://caml.inria.fr/pub/docs/manual-ocaml-4.08/manual035.html#sec265
>
> To describe my situation, I had a list l of int pairs which I could prove
> non-empty and I wanted to extract the first two ints.  I wrote
>
>   let (i, j) :: rest = l in ...
>
> and of course I got warning 8.  So I got interested in ways to suppress
> the warning, and I read about the attributes which are new to me and
> made me curious :P  I tried to insert
>
>   [@ocaml.warning "-8"]
>
> at many points in the code -- before the "let", before and after the
> equal sign, and before "in" -- but none of these ways got rid of the
> warning.  I gave up and used List.hd.  But I am still curious about the
> intended or correct usage of the attribute feature.
>
> Thanks.
>
> --
> Please don't Cc: me privately on mailing lists and Usenet,
> if you also post the followup to the list or newsgroup.
> To reply privately _only_ on Usenet and on broken lists
> which rewrite From, fetch the TXT record for no-use.mooo.com.

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

* Re: [Caml-list] How to use ocaml.warning
  2019-07-26  4:37 ` Nicolás Ojeda Bär
@ 2019-07-26 15:52   ` Ian Zimmerman
  2019-07-26 15:55     ` Nicolás Ojeda Bär
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Zimmerman @ 2019-07-26 15:52 UTC (permalink / raw)
  To: caml-list

On 2019-07-26 04:37, Nicolás Ojeda Bär wrote:

> In this case, you would want to attach the warning to the "let" binding:
> 
>     let[@warning "-8"] (i, j) :: rest = l in ...
> 
> Equivalently, you can use a postfix form:
> 
>     let (i, j) :: rest = l [@@warning "-8"] in ...
> 
> You can also attach the attribute to the whole "let" expression:
> 
>     (let (i, j) :: rest = l in ...) [@warning "-8"]
> 
> In this case, the warning is also disabled in the body of the "let"
> expression.
> 
> Going one step further, you can disable the warning on a whole section
> of a file by using a "floating" form of the attribute:
> 
>     [@@@warning "-8"]
>     ...
> 
> In this case, the warning will be disabled for any item appearing
> after the attribute.

Thanks.  But the manual says "ocaml.warning", not "warning".  What am I
misunderstanding?

-- 
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
To reply privately _only_ on Usenet and on broken lists
which rewrite From, fetch the TXT record for no-use.mooo.com.

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

* Re: [Caml-list] How to use ocaml.warning
  2019-07-26 15:52   ` Ian Zimmerman
@ 2019-07-26 15:55     ` Nicolás Ojeda Bär
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolás Ojeda Bär @ 2019-07-26 15:55 UTC (permalink / raw)
  To: Ian Zimmerman; +Cc: OCaml Mailing List

Hi Ian,

On Fri, Jul 26, 2019 at 5:53 PM Ian Zimmerman <itz@very.loosely.org> wrote:
>
> On 2019-07-26 04:37, Nicolás Ojeda Bär wrote:
>
> > In this case, you would want to attach the warning to the "let" binding:
> >
> >     let[@warning "-8"] (i, j) :: rest = l in ...
> >
> > Equivalently, you can use a postfix form:
> >
> >     let (i, j) :: rest = l [@@warning "-8"] in ...
> >
> > You can also attach the attribute to the whole "let" expression:
> >
> >     (let (i, j) :: rest = l in ...) [@warning "-8"]
> >
> > In this case, the warning is also disabled in the body of the "let"
> > expression.
> >
> > Going one step further, you can disable the warning on a whole section
> > of a file by using a "floating" form of the attribute:
> >
> >     [@@@warning "-8"]
> >     ...
> >
> > In this case, the warning will be disabled for any item appearing
> > after the attribute.
>
> Thanks.  But the manual says "ocaml.warning", not "warning".  What am I
> misunderstanding?

Actually both names are recognized. The long name ocaml.warning is to
be preferred when there is danger of shadowing (say, by a ppx
preprocessor).

Best wishes,
--
Nicolás OJEDA BÄR
nicolas.ojeda.bar@lexifi.com
https://www.lexifi.com

> --
> Please don't Cc: me privately on mailing lists and Usenet,
> if you also post the followup to the list or newsgroup.
> To reply privately _only_ on Usenet and on broken lists
> which rewrite From, fetch the TXT record for no-use.mooo.com.

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

end of thread, other threads:[~2019-07-26 15:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-26  2:14 [Caml-list] How to use ocaml.warning Ian Zimmerman
2019-07-26  4:37 ` Nicolás Ojeda Bär
2019-07-26 15:52   ` Ian Zimmerman
2019-07-26 15:55     ` Nicolás Ojeda Bär

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).