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 EFD11BB9C for ; Fri, 9 Dec 2005 16:26:31 +0100 (CET) Received: from comtv.ru (mail.comtv.ru [217.10.32.19]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jB9FQVuj011647 for ; Fri, 9 Dec 2005 16:26:31 +0100 X-UCL: actv Received: from av1474.oops ([10.0.66.9] verified) by comtv.ru (CommuniGate Pro SMTP 4.1.8) with ESMTP id 110114452; Fri, 09 Dec 2005 18:26:30 +0300 Date: Fri, 9 Dec 2005 18:26:43 +0300 (MSK) From: malc X-X-Sender: malc@home.oyster.ru To: Jacques Garrigue Cc: skaller@users.sourceforge.net, caml-list@yquem.inria.fr Subject: Re: [Caml-list] partial application warning unreliable? In-Reply-To: <20051209.111523.100788477.garrigue@math.nagoya-u.ac.jp> Message-ID: References: <20051208.121012.49167263.garrigue@math.nagoya-u.ac.jp> <1134092611.8940.57.camel@rosella> <20051209.111523.100788477.garrigue@math.nagoya-u.ac.jp> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at nez-perce with ID 4399A227.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; malc:01 malc:01 pulsesoft:01 caml-list:01 bug:01 endline:01 val:01 uncaught:01 arity:01 iter:01 inference:01 generalizing:01 -warn-error:01 ocaml:01 pulsesoft: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.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 On Fri, 9 Dec 2005, Jacques Garrigue wrote: > 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 :-( I gather all this means that the only "safe" way to call a unit method on an implictily typed object is via: let () = o#moo in ... -- mailto:malc@pulsesoft.com