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? |
Benjamin Geer wrote:
> 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)").
Curiously, it works if the class is parameterised instead of the method:
class type ['a] driver =
object
constraint 'a = #connection
method get_connection : db_name:string -> 'a
end
class mysql_driver =
object (self : 's)
constraint 's = #connection #driver
method get_connection ~(db_name:string) =
new mysql_connection db_name
end
Maybe something about these different approaches should go in a FAQ
somewhere.
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