From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA29518 for caml-redistribution; Wed, 21 May 1997 18:48:23 +0200 (MET DST) 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 QAA26537 for ; Wed, 21 May 1997 16:06:51 +0200 (MET DST) Received: from firewall.hd.ibm.de (firewall.hd.ibm.de [192.101.197.10]) by nez-perce.inria.fr (8.8.5/8.7.3) with SMTP id QAA09084 for ; Wed, 21 May 1997 16:04:39 +0200 (MET DST) Received: from kaa.heidelbg.ibm.com by firewall.hd.ibm.de (AIX 4.1/UCB 5.64/4.03/chkV1.0) id AA09032; Wed, 21 May 1997 16:03:35 +0200 Received: from idse.heidelbg.ibm.com by kaa.heidelbg.ibm.com (AIX 3.2/UCB 5.64/4.03) id AA32464; Wed, 21 May 1997 16:03:33 +0200 Received: by idse.heidelbg.ibm.com (AIX 3.2/UCB 5.64/4.03) id AA33541; Wed, 21 May 1997 16:03:32 +0200 Message-Id: <9705211403.AA33541@idse.heidelbg.ibm.com> X-Mailer: exmh version 1.6.4p2 10/10/95 (wish4.1) To: Donald Syme Cc: caml-list@inria.fr Subject: Re: OCaml's subtyping better than advertised? In-Reply-To: (Your message of Tue, 20 May 97 15:22:28 N.) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 21 May 97 16:03:32 +0100 From: Wolfgang Lux Sender: weis > One thing I'm wondering is why the syntax for O'Caml types has no > way of specifying interface inheritance easily? For > example, I want to define some object type (nb. I'm defining > a type not a class): > > type widget = < windowid: unit -> int, > set_height: int -> unit, > height: unit -> int, > .. >; > > [ Aside: at the moment I don't seem to be able to do this > in O'Caml, without defining a class, because the type > variable ".." is free. Perhaps there needs to be come > mechanism for defining new object types with the same > "#" behaviour of the types generated by classes? > This would then allow me to write "#widget" as a type > without having defined a class widget (i.e. without > having committed to an implementation) ] > This *can* easily be done by using virtual methods, e.g. virtual class widget () = virtual windowid: int (* unit -> ... is not necessary here! *) virtual set_height: int -> unit virtual height: int (* unit -> ... not necessary as well *) end > If I then want to define some structural subtype of #widget > (nb. not necessarily implemented by a subclass), I have to write out all > the methods again: > > type textual_widget = < windowid: unit -> int, > set_height: int -> unit, > height: unit -> int, > insert : string * int -> unit, > get : int * int -> string > .. >; > This is easily done as well: virtual class textual_widget () = inherit widget () virtual insert : string -> int -> unit virtual get : int -> int -> string end > > Yours, > Don Syme Regards Wolfgang > > P.S. Apologies for no french version. Apologies from me as well. ---- Wolfgang Lux WZH Heidelberg, IBM Germany Phone: +49-6221-59-4546 Fax: +49-6221-59-3500 Internet: lux@heidelbg.ibm.com Office: mazvm01(lux)