Browse thread
partial application warning unreliable?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-12-09 (01:43) |
From: | skaller <skaller@u...> |
Subject: | Re: [Caml-list] partial application warning unreliable? |
On Fri, 2005-12-09 at 02:51 +0300, malc wrote: > On Thu, 8 Dec 2005, Jacques Garrigue wrote: > > <snip> > > > > # class cc = object (self) > > method f x y = x + y > > method g () = self#f 1; > > end;; > > class cc : > > object method f : int -> int -> int method g : unit -> int -> int end > > > > No warning, for the reason stated above: the semicolon does nothing. > > Here's a strange test case, i was bitten by it recently in a real code: > > <mox.ml> > let y o = > o#moo; > 1 > > let x (o:(<moo : string -> unit>)) = > y o > > let _ = > print_int (x (object method moo s = print_endline s end)); > print_newline () > </mox.ml> > > # ocaml -warn-error A mox.ml > 1 > > In my case method moo was actually a method that locked a mutex, the > implications were quite severe. 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 = <fun> 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. -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net