caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolás Ojeda Bär" <nicolas.ojeda.bar@lexifi.com>
To: Ian Zimmerman <itz@very.loosely.org>
Cc: Caml Mailinglist <caml-list@inria.fr>
Subject: Re: [Caml-list] How to use ocaml.warning
Date: Fri, 26 Jul 2019 04:37:02 +0000	[thread overview]
Message-ID: <CADK7aFO3idJ2ecacQhm4fnMJp+jEAexT5StgWvy_cfdk=5N+xQ@mail.gmail.com> (raw)
In-Reply-To: <20190726021401.6u7mtlfy4exc756q@matica.foolinux.mooo.com>

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.

  reply	other threads:[~2019-07-26  4:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-26  2:14 Ian Zimmerman
2019-07-26  4:37 ` Nicolás Ojeda Bär [this message]
2019-07-26 15:52   ` Ian Zimmerman
2019-07-26 15:55     ` Nicolás Ojeda Bär

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADK7aFO3idJ2ecacQhm4fnMJp+jEAexT5StgWvy_cfdk=5N+xQ@mail.gmail.com' \
    --to=nicolas.ojeda.bar@lexifi.com \
    --cc=caml-list@inria.fr \
    --cc=itz@very.loosely.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).