Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Error: Type variables, that can not be generalized?!
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ 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 <> 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.


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 Archives:
Bug reports: FAQ:
Beginner's list: