From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr 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 14741BB81 for ; Fri, 9 Dec 2005 03:15:48 +0100 (CET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jB92Fj8P030182 for ; Fri, 9 Dec 2005 03:15:47 +0100 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id jB92FTuN018946; Fri, 9 Dec 2005 11:15:30 +0900 (JST) Date: Fri, 09 Dec 2005 11:15:23 +0900 (JST) Message-Id: <20051209.111523.100788477.garrigue@math.nagoya-u.ac.jp> To: skaller@users.sourceforge.net Cc: malc@pulsesoft.com, caml-list@yquem.inria.fr Subject: Re: [Caml-list] partial application warning unreliable? From: Jacques Garrigue In-Reply-To: <1134092611.8940.57.camel@rosella> References: <20051208.121012.49167263.garrigue@math.nagoya-u.ac.jp> <1134092611.8940.57.camel@rosella> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4398E8D1.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 bug:01 endline:01 val:01 uncaught:01 arity:01 iter:01 inference:01 generalizing:01 -warn-error:01 ocaml:01 sourceforge:01 partial:01 partial:01 behaviour:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 From: skaller > AHA. In trying to fill out your problem to a real test case > for a bug report .. I think I have discovered the problem! > > # class cow = object(self) method moo (s:string)= print_endline s > end;; > class cow : object method moo : string -> unit end > > # let y o = o#moo; 1;; > val y : < moo : 'a; .. > -> int = > > And there we have it .. an uncaught partial application! > > The reason is clear .. we don't know the arity of the > function yet -- we don't even know its type. > > The type of a statement is currently 'a, which is just > plain wrong. The correct type is void, however unit > will catch more errors than 'a. This behaviour has been known for long. This is for instance why, in the standard library, List.iter is explicitly given type ('a -> unit) -> 'a list -> unit rather than the inferred ('a -> 'b) -> 'a list -> unit (which actually it had a long time ago, in Caml Special Light) The trouble is that any change to this behaviour would not be principal (from the type inference point of view). That is, we might choose to instantiate 'a to unit when generalizing the type of y, but actually #moo might be of type int, which we will discover later, when applying it. As long as returning non-unit in a statement grades only a warning, we cannot do that. So, saying that the type of y above is wrong means that all statements should be forced by type checking to return unit and nothing else. This is not the default, but this could indeed be done with -warn-error S. Note that, for objects, there was before ocaml 3.05 a warning, turned on only in -labels mode, that ensured that every method was known before being called. This would have caught the above error. It is now commented out :-( Jacques Garrigue