Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2003-08-20 (16:19)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] does class polymorphism need to be so complicated?
On Wed, Aug 20, 2003 at 11:05:35AM -0500, Brian Hurt wrote:
> Instead of declaring obj to be printable, why not just declare that it has 
> a function print?  Like:
> class printer = 
>     object
>         method print (obj: <print: unit->unit>) = obj#print ();
>     end;;
> This removes the need for a coercion, as it gets around the need to 
> upcast.

Interesting. Am I right in thinking that the <print : unit -> unit>
type syntax can refer to _any_ object which has a print method,
regardless of class hierarchy?

This could be quite a fun feature, although I'm not quite sure of the
best way to use it ...


Richard Jones.
Merjis Ltd. - all your business data are belong to you.
'There is a joke about American engineers and French engineers. The
American team brings a prototype to the French team. The French team's
response is: "Well, it works fine in practice; but how will it hold up
in theory?"'

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: