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 WAA27170; Wed, 20 Aug 2003 22:46:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 WAA07170 for ; Wed, 20 Aug 2003 22:46:09 +0200 (MET DST) Received: from manzanita (63-217-154-71.greystoneapts.com [63.217.154.71]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h7KKk8T07444 for ; Wed, 20 Aug 2003 22:46:08 +0200 (MET DST) Received: from manzanita ([127.0.0.1] helo=ucdavis.edu) by manzanita with esmtp (Exim 3.36 #1 (Debian)) id 19pZnp-0000G1-00 for ; Wed, 20 Aug 2003 13:43:33 -0700 Message-ID: <3F43DD75.8020807@ucdavis.edu> Date: Wed, 20 Aug 2003 13:43:33 -0700 From: Issac Trotts Reply-To: ijtrotts@ucdavis.edu User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030319 Debian/1.3-3 X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] does class polymorphism need to be so complicated? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; issac:01 trotts:01 ijtrotts:01 caml-list:01 unit-:01 foo:01 val:01 upcast:01 bug:01 faq:01 beginner's:01 beginners:01 bin:01 caml-bugs:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Brian Hurt wrote: >On Wed, 20 Aug 2003, Benjamin Geer wrote: > > > >>class printer = >> object >> method print (obj : printable) = obj#print() >> end ;; >> >> > >Instead of declaring obj to be printable, why not just declare that it has >a function print? Like: > >class printer = > object > method print (obj: unit>) = obj#print (); > end;; > > You still have to up-cast objects having more methods than just 'print'. # class printer = object method print (o:) = o#print end;; # class foo = object method print = print_string "[foo]" end;; # class bar = object method print = print_string "[bar]" method frob = () end;; # let f = new foo;; val f : foo = # let p = new printer;; val p : printer = # let b = new bar;; val b : bar = # p#print f;; [foo]- : unit = () # p#print b;; Characters 8-9: p#print b;; ^ This expression has type bar = < frob : unit; print : unit > but is here used with type foo = < print : unit > Only the first object type has a method frob # p#print (b :> );; [bar]- : unit = () Issac >This removes the need for a coercion, as it gets around the need to >upcast. > >Brian > > >------------------- >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 > > > > ------------------- 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