From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8QJDa94005980 for ; Mon, 26 Sep 2011 21:13:36 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhcBAAvOgE7RVdQ2kGdsb2JhbABChGKjLAgUAQEBAQkJDQcUBCKBUwEBAQEDEgIPBFIQAQgCCw0CAiYCAiEBEgEFARwGEyKHXJ4BCosIkW2BLIROgREEk1KKF4JyPYQJ X-IronPort-AV: E=Sophos;i="4.68,445,1312149600"; d="scan'208";a="110613887" Received: from mail-vw0-f54.google.com ([209.85.212.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 26 Sep 2011 21:13:36 +0200 Received: by vws11 with SMTP id 11so10036160vws.27 for ; Mon, 26 Sep 2011 12:13:35 -0700 (PDT) Received: by 10.52.26.109 with SMTP id k13mr6497010vdg.192.1317064415150; Mon, 26 Sep 2011 12:13:35 -0700 (PDT) MIME-Version: 1.0 Sender: hcarty@mulethief.com Received: by 10.52.188.162 with HTTP; Mon, 26 Sep 2011 12:13:15 -0700 (PDT) In-Reply-To: References: From: "Hezekiah M. Carty" Date: Mon, 26 Sep 2011 15:13:15 -0400 X-Google-Sender-Auth: 5X8BEmxz07lJgRxOQhmGmkOTWwQ Message-ID: To: Pierre-Alexandre Voye Cc: caml-list Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p8QJDa94005980 X-Validation-by: hez@0ok.org Subject: Re: [Caml-list] Utopian idea ? On Fri, Sep 16, 2011 at 5:33 PM, Pierre-Alexandre Voye wrote: > > 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 ? > You need to provide some explicit types: class ['a, 'b] _DIRECTORY = object (self :'self) val mutable indexDico : ('a, 'b) Hashtbl.t = Hashtbl.create 128 val mutable dictionnaires : ('a, 'b) Hashtbl.t = 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 See the class section of the manual for more information: http://caml.inria.fr/pub/docs/manual-ocaml/manual005.html#toc27 I hope this helps. Hez