caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Esther Baruk <esther.baruk@gmail.com>
To: Philippe Wang <mail@philippewang.info>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list]Warning 20: this argument will not be used by the function.
Date: Wed, 31 Aug 2011 09:12:07 +0200	[thread overview]
Message-ID: <CAFzMiE2-a-a91y05i88L-ojiJpOY3tBZjg-aMg0HnKCyeB8JaQ@mail.gmail.com> (raw)
In-Reply-To: <CAAFfW_pSD0jUb7UWJZLXM=xkne3qwBZuGCFe9vW2gULOXXeBoA@mail.gmail.com>

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

In fact 'assert false' is explicitely replaced by 'raise
Assert_failure(...)' by the parser.
See the documentation about that in the "Language extensions" section.

With any other argument than false, assert is considered to have type bool
-> unit



Esther Baruk


On Wed, Aug 31, 2011 at 1:40 AM, Philippe Wang <mail@philippewang.info>wrote:

> On Wed, Aug 31, 2011 at 12:31 AM, John Carr <jfc@mit.edu> wrote:
> > # let f () = assert false; 0;;
> > Warning 21: this statement never returns (or has an unsound type.)
> > val f : unit -> int = <fun>
>
> > Assert behaves like a function with type bool -> 'a.  The return type is
> > an unconstrained type, a type variable not mentioned on the left hand
> > side of the arrow.
>
> Actually, assert is more like a function with type bool -> unit.
> Indeed, (assert false) is a special case where it is "so obvious that
> it'll raise an exception that it's made type 'a".
>
> Notably, if you write
> assert(1=2)
> it's not "obvious enough" for the compiler to assume it will raise an
> exception.
> (Which is normal, by the way, because it's generally an undecidable
> problem: in general, it's not possible to know that the evaluation of
> assert's argument will return a value, especially when there is a
> function application such as in "1=2".)
>
> So,
> in
> let f () = assert false
> f : unit -> 'a
> let f () = assert (1=2)
> f : unit -> unit
>
> And while
> let f () = assert false; 0;;
> raises a warning,
> let f () = assert (1=2); 0;;
> won't raise any.
>
> Somehow, the choice of discriminating (assert false) is not so perfect...
>
> Cheers,
>
> --
> Philippe Wang
>
>
> N.B. Sorry for double-replying.
> I wonder if "reply-to: caml-list@inria.fr" field could be added
> automatically to headers of all mails received by the list...
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/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: 3106 bytes --]

      reply	other threads:[~2011-08-31  7:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-30 11:27 AUGER Cedric
2011-08-30 22:31 ` John Carr
2011-08-30 23:40   ` Philippe Wang
2011-08-31  7:12     ` Esther Baruk [this message]

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=CAFzMiE2-a-a91y05i88L-ojiJpOY3tBZjg-aMg0HnKCyeB8JaQ@mail.gmail.com \
    --to=esther.baruk@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=mail@philippewang.info \
    /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).