From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8GLXl3t021685 for ; Fri, 16 Sep 2011 23:33:47 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AooBAPa/c07RVdW2kGdsb2JhbABBhFWiBn0IFAEBAQEJCQ0HFAQhgWwCDwQZARseAxIDBgc3AiQBEQEFASIbGodZlQuCWAqKf0KCWoUaO4htAgMGhWGBEQSTSo0BPYNw X-IronPort-AV: E=Sophos;i="4.68,395,1312149600"; d="scan'208";a="120173882" Received: from mail-yx0-f182.google.com ([209.85.213.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 16 Sep 2011 23:33:42 +0200 Received: by yxk36 with SMTP id 36so5084344yxk.27 for ; Fri, 16 Sep 2011 14:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=zmmnYs4qCXdDhAoMFHZewagmRhhtD1caWqGnMN3MI4o=; b=bMRBg4cLL5hcC1YCOPLsLZe96P9GJ2jHCgMz1uTwros4OF+VZl+wUccyPF8a1S6Vjy 2TmJZPn1HgrSZ0ZtTso7MRO/4vyf8zdwKQ4Y9H+B54X4RgZPehy2CfCku/6Sp2W/bQES WFrCjLrYwj1rK7fsXXCFySrSAdjS8oS6i2MkU= Received: by 10.236.37.134 with SMTP id y6mr18066561yha.113.1316208821147; Fri, 16 Sep 2011 14:33:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.111.13 with HTTP; Fri, 16 Sep 2011 14:33:21 -0700 (PDT) From: Pierre-Alexandre Voye Date: Fri, 16 Sep 2011 23:33:21 +0200 Message-ID: To: caml-list Content-Type: multipart/alternative; boundary=20cf303a31413c16ca04ad15bf5b Subject: [Caml-list] Utopian idea ? --20cf303a31413c16ca04ad15bf5b Content-Type: text/plain; charset=UTF-8 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 --20cf303a31413c16ca04ad15bf5b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello,

i'm writting an object which implements a directory servi= ce. The goal is to be able to add dynamically directories.
My directory= links IDs to different type of object.
Thus the object would contain se= veral hashtables where the key is a string (the ID), and the value an objec= t.
Of course, each hashtable would contain only a type.
For instance, the f= irst 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 co= mpiler doesn't accept it because it doesn't know the type of object= .

So here the code :

class _DIRECTORY =3D object=C2=A0 (self = :'self)
=C2=A0=C2=A0=C2=A0 val mutable indexDico =3D Hashtbl.create 128
=C2=A0= =C2=A0=C2=A0 val mutable dictionnaires =3D=C2=A0 Hashtbl.create 128
=C2= =A0=C2=A0=C2=A0 val mutable maxIndex =3D 0
=C2=A0=C2=A0=C2=A0 method get= Dict =3D dictionnaires
=C2=A0=C2=A0=C2=A0 method getIndex =3D indexDico<= br>=C2=A0=C2=A0=C2=A0 method getMaxIndex =3D maxIndex
=C2=A0=C2=A0=C2=A0 method incMaxIndex =3D maxIndex <- (self#getMaxIndex = +1)
=C2=A0=C2=A0=C2=A0 method addDict (name:string) =3D (self#incMaxInde= x) ;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 let elem =3D Hashtbl.create 128 in Hashtbl.add (self#getInd= ex) name elem
=C2=A0 end;;
=C2=A0
Error: Some type variables are unbound in this t= ype:
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 class _DIRECTORY :=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 object
= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 va= l mutable dictionnaires : ('a, 'b) Hashtbl.t
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 val mutable indexDic= o : (string, ('c, 'd) Hashtbl.t) Hashtbl.t
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 va= l mutable maxIndex : int
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 method addDict : string -> unit
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 method getD= ict : ('a, 'b) Hashtbl.t
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 method getIndex : (string, ('c, '= d) Hashtbl.t) Hashtbl.t
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 me= thod getMaxIndex : int
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 method incMaxIndex : unit
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 end
=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 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.or= g/users/montaigne

--20cf303a31413c16ca04ad15bf5b--