From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p7V7CvIh003012 for ; Wed, 31 Aug 2011 09:12:57 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am8CAGveXU7RVdi2kGdsb2JhbABCmGqHQIgVCBQBAQEBCQkNBxQEIYFAAQEBAQIBEgITGQEbEgsBAwELBgUEBwMKDSEiAREBBQEKAREGExIQh1AEmFEKjDyCVYUzO4htAgMGhk8EglSQUYxhPINq X-IronPort-AV: E=Sophos;i="4.68,306,1312149600"; d="scan'208";a="107188576" Received: from mail-qy0-f182.google.com ([209.85.216.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 31 Aug 2011 09:12:28 +0200 Received: by qyk9 with SMTP id 9so282999qyk.6 for ; Wed, 31 Aug 2011 00:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=R2I7ZP6Dzu+PoORwH15bOAVlkyC4WVzvTjz9rlrPVqQ=; b=W8bGTAaPHwWtq8o0KTnLJS44wxqa8MuD/dnFaVbjdzfAHl+vvxy1YQiCk+wBZHIx4q D3oX67XnX1c/w9zNsB0U1It2/eB+lcYUwTIR4glVifvJfwLhWhTBXqXbGkQPl8t1UxBr P6I3c9j2bdq29XCBHLx0Lqw3ujVzgZP1TmTQw= Received: by 10.229.101.34 with SMTP id a34mr48308qco.8.1314774747280; Wed, 31 Aug 2011 00:12:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.19.213 with HTTP; Wed, 31 Aug 2011 00:12:07 -0700 (PDT) In-Reply-To: References: <20110830132737.78b7a08e@lri.fr> <201108302231.p7UMVvoB024895@outgoing.mit.edu> From: Esther Baruk Date: Wed, 31 Aug 2011 09:12:07 +0200 Message-ID: To: Philippe Wang Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=0016364ee5f2c5748304abc7d938 Subject: Re: [Caml-list]Warning 20: this argument will not be used by the function. --0016364ee5f2c5748304abc7d938 Content-Type: text/plain; charset=ISO-8859-1 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 wrote: > On Wed, Aug 31, 2011 at 12:31 AM, John Carr wrote: > > # let f () = assert false; 0;; > > Warning 21: this statement never returns (or has an unsound type.) > > val f : unit -> int = > > > 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 > > --0016364ee5f2c5748304abc7d938 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable In fact 'assert false' is explicitely replaced by 'raise Assert= _failure(...)' by the parser.
See the documentation about that in t= he "Language extensions" section.

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



Esther Baruk


On Wed, Aug 31, 2011 at 1:40 AM, Philipp= e Wang <mail= @philippewang.info> wrote:
On Wed, Aug 31, 2011 at 12:31 AM, John Carr <jfc@mit.edu> wrote:
> # let f () =3D assert false; 0;;
> Warning 21: this statement never returns (or has an unsound type.)
> val f : unit -> int =3D <fun>

> Assert behaves like a function with type bool -> 'a. =A0The ret= urn type is
> an unconstrained type, a type variable not mentioned on the left hand<= br> > 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<= br> it'll raise an exception that it's made type 'a".

Notably, if you write
assert(1=3D2)
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=3D2".)

So,
in
let f () =3D assert false
f : unit -> 'a
let f () =3D assert (1=3D2)
f : unit -> unit

And while
let f () =3D assert false; 0;;
raises a warning,
let f () =3D assert (1=3D2); 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. =A0Subscription 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


--0016364ee5f2c5748304abc7d938--