caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Error: Type variables, that can not be generalized?!
@ 2003-02-20 19:50 Oliver Bandel
  2003-02-20 19:54 ` Basile STARYNKEVITCH
  0 siblings, 1 reply; 5+ messages in thread
From: Oliver Bandel @ 2003-02-20 19:50 UTC (permalink / raw)
  To: caml-list

Hello,


I'm teseting my code in the toplevel, and see no problems.
I use the ocamlc-compiler and it produces this message:


  "The type of this expression, ('_a, `_b) Hashtbl.t,
   contains type variables that cannot be generalized"

The line, where the problem occured was an unused
Hashtable-Creation.

When I removed that line, or when I added a Hashtbl.add,
the message disappeared.

Why is this a problem?

The line was:
  let entry_hash = Hashtbl.create 100000

The added line, which lets the error-message disappears
was:

   Hashtbl.add entry_hash "foo" "bar"


Any hints, ewhat the problem is?


Regards,
   Oliver
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Caml-list] Error: Type variables, that can not be generalized?!
  2003-02-20 19:50 [Caml-list] Error: Type variables, that can not be generalized?! Oliver Bandel
@ 2003-02-20 19:54 ` Basile STARYNKEVITCH
  2003-02-21  3:30   ` John Max Skaller
  0 siblings, 1 reply; 5+ messages in thread
From: Basile STARYNKEVITCH @ 2003-02-20 19:54 UTC (permalink / raw)
  To: caml-list

>>>>> "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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Error: Type variables, that can not be generalized?!
  2003-02-20 19:54 ` Basile STARYNKEVITCH
@ 2003-02-21  3:30   ` John Max Skaller
  2003-02-21 16:20     ` Gérard Huet
  0 siblings, 1 reply; 5+ messages in thread
From: John Max Skaller @ 2003-02-21  3:30 UTC (permalink / raw)
  To: Basile STARYNKEVITCH; +Cc: caml-list

Basile STARYNKEVITCH wrote:


> The compiled unit needs to know the type of its hashtable (I don't
> know why). 


The reason is: the interpreter is building a top level program.
The compiler isn't: it's building a module. That hashtable might
be used by code in another module, and so its type
must be known so external client use can be type checked
against the type of the hashtable.

The only way to use the hashtable from the interpreter is in the top
level and the first such use will (usually) fix the type against
which subsequent uses can be checked, so the type doesn't have to
be fixed until the first use.

[What I said isn't quite precise, for example:

	let h = Hashtble.create 97 in
	Hashtbl.add 1 []
	;;

Here the type *still* isn't fixed even on the first use :=]

BTW: I've always been baffled by the seeminly wrong nomenclature
'generalisation' when in fact unification involves *specialising*
types/type variables. Does it refer to the seeking of the
'most general' unifier -- that is, the most general specialisation?

Error messages like

"The type of this expression, ('_a, `_b) Hashtbl.t,
contains type variables that cannot be generalized"

seem counterintuitive when in fact the problem is
that variables can't be made specific enough.

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Error: Type variables, that can not be generalized?!
  2003-02-21  3:30   ` John Max Skaller
@ 2003-02-21 16:20     ` Gérard Huet
  0 siblings, 0 replies; 5+ messages in thread
From: Gérard Huet @ 2003-02-21 16:20 UTC (permalink / raw)
  To: John Max Skaller; +Cc: caml-list


Le vendredi, 21 fév 2003, à 04:30 Europe/Paris, John Max Skaller a 
écrit :

> BTW: I've always been baffled by the seeminly wrong nomenclature
> 'generalisation' when in fact unification involves *specialising*
> types/type variables. Does it refer to the seeking of the
> 'most general' unifier -- that is, the most general specialisation?
>
> Error messages like
>
> "The type of this expression, ('_a, `_b) Hashtbl.t,
> contains type variables that cannot be generalized"
>
> seem counterintuitive when in fact the problem is
> that variables can't be made specific enough.

Generalisation refers to transforming a free type variable into a 
universally quantified type
variable. Hindley-Milner polymorphism is more than first order 
unification, it allows
instantiation of a variable by types mutually incompatible. This is why 
ML allows
let i x = x in (i "a",i 0) c
because i has a truly polymorphic type a -> a, which get instantiated 
in string -> string
and int -> int, even though string and int are not unifiable.
Or even better :
  let i x = x in (i i);;
  - : '_a -> '_a = <fun>
and indeed :
let foo = let i x = x in (i i) in (foo foo);;
This expression has type 'a -> 'a but is here used with type 'a

The trick is that "let x=M in N" is treated differently from the redex 
(fun x->N)M,
and rather like M[x<-N] where the various occurrences of x may receive 
different type
assignments

GH



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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [Caml-list] Error: Type variables, that can not be generalized?!
@ 2003-02-21  0:23 Arturo Borquez
  0 siblings, 0 replies; 5+ messages in thread
From: Arturo Borquez @ 2003-02-21  0:23 UTC (permalink / raw)
  To: Oliver Bandel; +Cc: caml-list

oliver@first.in-berlin.de (Oliver Bandel) wrote:

Easy, when you add to the code the line adding an element
to the hash table you've also tell to the type system that
the hash table had a concrete type. Same problem will be
raised with an empty list [] wich is never used.

Regards

Arturo 

>Hello,
>
>
>I'm teseting my code in the toplevel, and see no problems.
>I use the ocamlc-compiler and it produces this message:
>
>
>  "The type of this expression, ('_a, `_b) Hashtbl.t,
>   contains type variables that cannot be generalized"
>
>The line, where the problem occured was an unused
>Hashtable-Creation.
>
>When I removed that line, or when I added a Hashtbl.add,
>the message disappeared.
>
>Why is this a problem?
>
>The line was:
>  let entry_hash = Hashtbl.create 100000
>
>The added line, which lets the error-message disappears
>was:
>
>   Hashtbl.add entry_hash "foo" "bar"
>
>
>Any hints, ewhat the problem is?
>
>
>Regards,
>   Oliver
>-------------------
>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
>


-- 
Arturo Borquez


__________________________________________________________________
The NEW Netscape 7.0 browser is now available. Upgrade now! http://channels.netscape.com/ns/browsers/download.jsp 

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-02-21 16:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-20 19:50 [Caml-list] Error: Type variables, that can not be generalized?! Oliver Bandel
2003-02-20 19:54 ` Basile STARYNKEVITCH
2003-02-21  3:30   ` John Max Skaller
2003-02-21 16:20     ` Gérard Huet
2003-02-21  0:23 Arturo Borquez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).