Hello,

i'm writting an object which implements a directory service. The goal is to be able to add dynamically directories.
My directory links IDs to different type of object.
Thus the object would contain several hashtables where the key is a string (the ID), and the value an object.
Of course, each hashtable would contain only a type.
For instance, the first hashtable is the directory of object "ant", the second "cheese", etc...
An "index" hashtable allow to register a new hashtable for a new type

I implemented the directory, and as i expected i had a problem : the compiler doesn't accept it because it doesn't know the type of object.

So here the code :

class _DIRECTORY = object  (self :'self)
    val mutable indexDico = Hashtbl.create 128
    val mutable dictionnaires =  Hashtbl.create 128
    val mutable maxIndex = 0
    method getDict = dictionnaires
    method getIndex = indexDico
    method getMaxIndex = maxIndex
    method incMaxIndex = maxIndex <- (self#getMaxIndex +1)
    method addDict (name:string) = (self#incMaxIndex) ;
                           let elem = Hashtbl.create 128 in Hashtbl.add (self#getIndex) name elem
  end;;
 
Error: Some type variables are unbound in this type:
         class _DIRECTORY :
           object
             val mutable dictionnaires : ('a, 'b) Hashtbl.t
             val mutable indexDico : (string, ('c, 'd) Hashtbl.t) Hashtbl.t
             val mutable maxIndex : int
             method addDict : string -> unit
             method getDict : ('a, 'b) Hashtbl.t
             method getIndex : (string, ('c, 'd) Hashtbl.t) Hashtbl.t
             method getMaxIndex : int
             method incMaxIndex : unit
           end
       The method getDict has type ('a, 'b) Hashtbl.t where 'b is unbound


It doen't surprised me anymore, but i there a strategy to allow that and to get round this difficulties ?

Thank you for your ideas.

Regards,

Pierre-Alex

--
---------------------
https://twitter.com/#!/ontologiae/
http://linuxfr.org/users/montaigne