From: Pierre-Alexandre Voye <ontologiae@gmail.com>
To: caml-list <caml-list@inria.fr>
Subject: [Caml-list] Utopian idea ?
Date: Fri, 16 Sep 2011 23:33:21 +0200 [thread overview]
Message-ID: <CANnJ5GcjDYGyv7TUfqz6v3t8mG0rUtyFVh3wbHHQooLSm7uBJQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2019 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 2645 bytes --]
next reply other threads:[~2011-09-16 21:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-16 21:33 Pierre-Alexandre Voye [this message]
2011-09-26 19:13 ` Hezekiah M. Carty
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=CANnJ5GcjDYGyv7TUfqz6v3t8mG0rUtyFVh3wbHHQooLSm7uBJQ@mail.gmail.com \
--to=ontologiae@gmail.com \
--cc=caml-list@inria.fr \
/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