From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA26735 for caml-redistribution; Thu, 4 Nov 1999 19:47:31 +0100 (MET) 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 WAA29692 for ; Wed, 3 Nov 1999 22:45:59 +0100 (MET) Received: from saul.cis.upenn.edu (SAUL.CIS.UPENN.EDU [158.130.12.4]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id WAA27083 for ; Wed, 3 Nov 1999 22:45:57 +0100 (MET) Resent-From: vouillon@saul.cis.upenn.edu Received: (from vouillon@localhost) by saul.cis.upenn.edu (8.8.5/8.8.5) id QAA13420 for caml-list@inria.fr; Wed, 3 Nov 1999 16:45:56 -0500 (EST) Resent-Message-Id: <199911032145.QAA13420@saul.cis.upenn.edu> Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by saul.cis.upenn.edu (8.8.5/8.8.5) with ESMTP id QAA10856 for ; Wed, 3 Nov 1999 16:40:34 -0500 (EST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id WAA26905 for ; Wed, 3 Nov 1999 22:40:32 +0100 (MET) Received: (from vouillon@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA15099 for vouillon@saul.cis.upenn.edu; Wed, 3 Nov 1999 22:40:32 +0100 (MET) Received: (from vouillon@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA27683; Wed, 3 Nov 1999 22:40:29 +0100 (MET) Message-ID: <19991103224029.11296@pauillac.inria.fr> Date: Wed, 3 Nov 1999 22:40:29 +0100 From: Jerome Vouillon To: Christian RINDERKNECHT Subject: Re: [Q] Four micro-questions on objects and modules. References: <19991102140952.A16438@jones.int-evry.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 0.89.1 In-Reply-To: <19991102140952.A16438@jones.int-evry.fr>; from Christian RINDERKNECHT on Tue, Nov 02, 1999 at 02:09:52PM +0100 X-Loop: Jerome.Vouillon@inria.fr Resent-Date: Wed, 3 Nov 1999 16:45:56 -0500 Resent-To: caml-list@inria.fr Sender: weis Hello, > 1) Assume I compile m.ml made of: class c = object end > and m.mli: class c : object end > > Now: > > Objective Caml version 2.02 > > # #load "m.cmo";; > # let f = fun (x : #M.c) -> x;; > val f : (#M.c as 'a) -> 'a = > > OK. What strikes me is: > > # let g = fun (x : M.c) -> x;; > val g : M.c -> M.c = > > What is the difference between f and g? If the type of g is > equivalent to #M.c -> #M.c, then according to the manual (#-types) > there is a difference, isn'it? If you remove the abbreviations, the type of f is (< .. > as 'a) -> 'a So, this function can be applied to any object and returns an object of the same type (you should understand the ellipsis as a type variable that can be instantiated to any row of methods). If it had type #M.c -> #M.c, that is, < .. > -> < .. > then, it could be apply to any object and would returns an object of any type. You cannot write a function of this type unless it never terminates or always raises an exception. Finally, the type of g is < > -> < > This function can only be applied to an object with no method (you can actually apply it to any object by using a coercion first), and it returns an object with no method. > Moreover, I tought "M.c" was not syntactically correct when "c" > is a class (hence the "#" symbol)... > > 2) What is the semantics of the syntactic productions > (http://caml.inria.fr/ocaml/htmlman/node6.5.html): > > typexpr : typexpr # class-path > | ( typexpr {, typexpr}) # class-path A class defines two type abbreviations: here M.c and #M.c. The first one is the type of an object of this class. The second one is more general, and is the type of any object that has at least the methods of class M.c, but may have more methods. In particular the type of an object of any subclass of M.c will be an instance of type #M.c. > 3) Would it be possible to allow the "include" feature in class > types? What do you mean ? A class type can inherit from another class type : class type c = object method m : int end class type d = object inherit c method n : bool end > 4) With values one can equivalently write: > > # let (h : unit -> unit) = fun x -> x;; > val h : unit -> unit = > > or > # let h = ((fun x -> x) : unit -> unit);; > val h : unit -> unit = > > I prefer the former when the function expression is big and I don't > want my eyes to read it only in order to find the type annotation > at the end. > > For the same sake, I think it would be consistent and useful to > allow class types, module types to qualify directly the module > names and the class names: > > # module (M : S) = struct (* lot of stuff here *) end;; > ^ > Not a Syntax error! > > and > > # class (x : ct) = object (* lot of stuff here *) end;; > ^ > Not a Syntax error! > > ...and the same for method and value instances. You can also write let h : unit -> unit = fun x -> x;; (without parentheses) The same syntax is also accepted for modules and classes. -- Jérôme