From: Philippe Wang <mail@philippewang.info>
To: caml-list@inria.fr
Subject: Re: [Caml-list]Warning 20: this argument will not be used by the function.
Date: Wed, 31 Aug 2011 01:40:17 +0200 [thread overview]
Message-ID: <CAAFfW_pSD0jUb7UWJZLXM=xkne3qwBZuGCFe9vW2gULOXXeBoA@mail.gmail.com> (raw)
In-Reply-To: <201108302231.p7UMVvoB024895@outgoing.mit.edu>
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...
next prev parent reply other threads:[~2011-08-30 23:40 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 [this message]
2011-08-31 7:12 ` Esther Baruk
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='CAAFfW_pSD0jUb7UWJZLXM=xkne3qwBZuGCFe9vW2gULOXXeBoA@mail.gmail.com' \
--to=mail@philippewang.info \
--cc=caml-list@inria.fr \
/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