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 (23:39)
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 =
   constraint 'a = #connection
   method get_connection : db_name:string -> 'a

class mysql_driver =
object (self : 's)
   constraint 's = #connection #driver
   method get_connection ~(db_name:string) =
     new mysql_connection db_name

Maybe something about these different approaches should go in a FAQ 


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