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-21 (20:24)
From: Benjamin Geer <ben@s...>
Subject: Re: [Caml-list] does class polymorphism need to be so complicated? wrote:
> I think the burden is very slight, but I have no problem at all with using 
> functions outside of objects. Realistic implementations would provide 
> coercion functions for every base class you want to coerce to, perhaps 
> named something like "as_base_class_name". Using the exmaple you give in 
> another message, we get something like this [...]

Thanks for the example; I think I can live with the approach you 
propose. :)  I agree with you (and Scott Meyers) about functions outside 
of objects being a good thing, as long as they're doing something 
useful, and not just working around syntactical problems.  Or at least 
as long as I don't have to write a large number of them.  With the 
approach you suggest, it looks like I only need one coercion function 
per base class, which I agree isn't too burdensome:

> let as_connection o = (o : #connection :> connection);;

I'm still curious to know why the example I gave (returning a 
mysql_connection from a method that was typed to return a #connection) 
didn't compile, though ("This method has type string -> mysql_connection 
which is less general than 'a. string -> (#connection as 'a)").


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