From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 9D357BC2F for ; Fri, 26 Nov 2004 20:14:50 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iAQJEnCp022534 for ; Fri, 26 Nov 2004 20:14:50 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA18849 for ; Fri, 26 Nov 2004 20:14:49 +0100 (MET) Received: from herd.plethora.net (herd.plethora.net [205.166.146.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iAQJElKU022529 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 26 Nov 2004 20:14:48 +0100 Received: from bhurt.plethora.net (bhurt.plethora.net [205.166.146.49]) by herd.plethora.net (8.13.1/8.12.11) with ESMTP id iAQJEbKp000815 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 26 Nov 2004 13:14:41 -0600 (CST) Date: Fri, 26 Nov 2004 13:16:17 -0600 (CST) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: skaller Cc: Nicolas Cannasse , caml-list Subject: Re: [Caml-list] Why doesn't ocamlopt detect a missing ; after failwith statement? In-Reply-To: <1101427906.9291.107.camel@pelican.wigram> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 41A780A9.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41A780A7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocamlopt:01 failwith:01 wrote:01 cannasse:01 wrote:01 val:01 failwith:01 prerr:01 endline:01 unify:01 unify:01 prerr:01 endline:01 ocaml:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: On 26 Nov 2004, skaller wrote: > On Fri, 2004-11-26 at 08:14, Nicolas Cannasse wrote: > > > All well and good, but I don't understand why it doesn't warn me about > > > the missing ';' in the first case. > > > > val failwith : string -> 'a > > > > so failwith "error" prerr_endline "OK"; > > > > is a valid call since 'a unify with (string -> unit) -> string -> unit > > .. a problem which could not occur were there a void type > which couldn't unify with 'a, and prerr_endline had > type string-> void. > > There is one- it's called unit. And prerr_endline probably already uses it. The problem isn't with prerr_endline, the "problem" is with failwith. failwith needs to return 'a, as it doesn't return. If it returned some other type, I couldn't write code like: if some_test then failwith "some_test" else some_value To make the above expression type correctly, failwith has to return the same type as some_value- which could be anything. Therefor, failwith needs to return 'a, a value which can unify with (be the same type as) anything else. The next problem comes in how Ocaml decides when and to what to apply arguments. Consider the expression: f [1;2;3] Fairly obvious, right? We're calling f with an argument of an int list. Not necessarily. Consider: List.map f [1;2;3] Now f, instead of being the function we're passing arguments into, is now an argument itself. So now, this is exactly the problem we're running into- prerr_endling is being treated exactly like f above- one minor change, and it's getting turned into an argument when it's meant to be a function call. Does this help? Brian