Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] does class polymorphism need to be so complicated?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi Vanicat <vanicat@l...>
Subject: Re: [Caml-list] does class polymorphism need to be so complicated?
Richard Jones <rich@annexia.org> writes:

> On Thu, Aug 21, 2003 at 01:44:23PM +0200, Remi Vanicat wrote:
>> Benjamin Geer <ben@socialtools.net> writes:
>> > 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 ;;
>
> Is there a way to add extra methods to my_printer_talker?

Yes. Add them. the constraint 's = #foo only say that the current
class must have at least the method specified in foo, and with the
the type specified in foo. but you can still make the type grow.

-- 
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