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?
Benjamin Geer <ben@socialtools.net> 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