Browse thread
[Caml-list] does class polymorphism need to be so complicated?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Benjamin Geer <ben@s...> |
| Subject: | Re: [Caml-list] does class polymorphism need to be so complicated? |
brogoff@speakeasy.net 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)").
Ben
-------------------
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