From: "Hezekiah M. Carty" <hez@0ok.org>
To: Pierre-Alexandre Voye <ontologiae@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Utopian idea ?
Date: Mon, 26 Sep 2011 15:13:15 -0400 [thread overview]
Message-ID: <CAMfPyLBv2m5aqNVtszbokDwy4qOJmFAOmg08rOoN+4BJAe5kmA@mail.gmail.com> (raw)
In-Reply-To: <CANnJ5GcjDYGyv7TUfqz6v3t8mG0rUtyFVh3wbHHQooLSm7uBJQ@mail.gmail.com>
On Fri, Sep 16, 2011 at 5:33 PM, Pierre-Alexandre Voye
<ontologiae@gmail.com> 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
prev parent reply other threads:[~2011-09-26 19:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-16 21:33 Pierre-Alexandre Voye
2011-09-26 19:13 ` Hezekiah M. Carty [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMfPyLBv2m5aqNVtszbokDwy4qOJmFAOmg08rOoN+4BJAe5kmA@mail.gmail.com \
--to=hez@0ok.org \
--cc=caml-list@inria.fr \
--cc=ontologiae@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox