From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA26767; Thu, 21 Aug 2003 13:44:19 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA26296 for ; Thu, 21 Aug 2003 13:44:17 +0200 (MET DST) Received: from mwinf0304.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.28]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h7LBiGf00982 for ; Thu, 21 Aug 2003 13:44:17 +0200 (MET DST) Received: from debian (ca-bordeaux-16-155.w80-8.abo.wanadoo.fr [80.8.88.155]) by mwinf0304.wanadoo.fr (SMTP Server) with ESMTP id C0DD2A80409E for ; Thu, 21 Aug 2003 13:44:16 +0200 (CEST) Received: from moi by debian with local (Exim 3.36 #1 (Debian)) id 19pnrb-0001rw-00 for ; Thu, 21 Aug 2003 13:44:23 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] does class polymorphism need to be so complicated? References: <3F43E250.1040903@socialtools.net> <20030821092849B.garrigue@kurims.kyoto-u.ac.jp> <3F448015.8090106@socialtools.net> <20030821175808V.garrigue@kurims.kyoto-u.ac.jp> <3F449301.8050500@socialtools.net> From: Remi Vanicat Mail-Copy-To: never Date: Thu, 21 Aug 2003 13:44:23 +0200 In-Reply-To: <3F449301.8050500@socialtools.net> (Benjamin Geer's message of "Thu, 21 Aug 2003 10:38:09 +0100") Message-ID: <873cfvz148.dlv@wanadoo.fr> User-Agent: Gnus/5.090024 (Oort Gnus v0.24) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 jacques:01 implements:01 garrigue:01 dept-info:01 labri:01 u-bordeaux:01 writes:01 remi:01 vanicat:01 syntax:02 unit:03 wrote:03 obj:03 interface:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Benjamin Geer writes: > Jacques Garrigue wrote: >> OK, there's also another way to do it, without inheritance. I just >> tried not to be confusing. >> class type printer = object >> method virtual print : #printable -> unit >> end >> class my_printer () = object (self : #printer) >> method print obj = ... >> end >> Looks a bit strange at first, but it does the work. > > Is there a way to write a class that implements more than one > interface? I've tried the following, but it produces a syntax error: > > class type virtual printer = object > method virtual print : #printable -> unit > end ;; > > class type virtual talker = object > method virtual talk : #printable -> unit > end ;; > > class my_printer_talker () = object (self : #printer; #talker) > method print obj = (* ... *) > method talk obj = (* ... *) > end ;; well this work : class my_printer_talker () = object (self : 's) constraint 's = #printer constraint 's = #talker method print obj = (* ... *) method talk obj = (* ... *) end ;; -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners