Browse thread
[Caml-list] Error: Type variables, that can not be generalized?!
-
oliver@f...
- Basile STARYNKEVITCH
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Basile STARYNKEVITCH <basile@s...> |
| Subject: | [Caml-list] Error: Type variables, that can not be generalized?! |
>>>>> "Oliver" == Oliver Bandel <oliver@first.in-berlin.de> writes:
Oliver> Hello, I'm teseting my code in the toplevel, and see no
Oliver> problems. I use the ocamlc-compiler and it produces this
Oliver> message:
Oliver> "The type of this expression, ('_a, `_b) Hashtbl.t,
Oliver> contains type variables that cannot be generalized"
The type ('_a, `_b) Hashtbl.t means:
there exist a type '_a, there exist a type '_b, such that
the displayed type is hashtable of key '_a and value '_b
The type ('a,'b) Hashtbl.t means:
for any type 'a and any type 'b, the displayed type is an hashtable
of key 'a & value 'b
Oliver> The line, where the problem occured was an unused
Oliver> Hashtable-Creation.
Oliver> The line was: let entry_hash = Hashtbl.create 100000
Oliver> The added line, which lets the error-message disappears
Oliver> was:
Oliver> Hashtbl.add entry_hash "foo" "bar"
Oliver> Any hints, ewhat the problem is?
The compiled unit needs to know the type of its hashtable (I don't
know why). An alternative was to code:
let entry_hash =
((Hashtbl.create 100000) : ((string,string) Hashtbl.t)
this means that you explicitly cast the type. The compiler then infers
other type taking into acount your explicit type.
In practice I find useful to explicitly cast like above the type of
every hashtable I create.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net
alias: basile<at>tunes<dot>org
8, rue de la Faïencerie, 92340 Bourg La Reine, France
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners