I've been working with some of the new features introduced with GADTs, and ran into a confusing instance of the "type variables that cannot be generalized" error.

The simplified program is as follows:
type _ field = Int : int -> 'a field
let a = Int 3
let b = Int (1 + 2)
let inside = 1 + 2
let c = Int inside

ocamlc -i returns:
type _ field = Int : int -> 'a field
val a : 'a field
val b : '_a field
val inside : int
val c : 'a field

with b remaining non-generalized. The problem I'm having with it is that the type variable doesn't depend on the value at all, so I don't see how that can prevent generalization.

Also, the manual says the reason some types aren't generalized is due to "polymorphic mutable data structures". Nothing I created is mutable, so why was generalization turned off in the first place?

Finally, I'm confused why separating the function from the definition is enough to fix this; c is generalized simply by defining 1+2 in a separate value (which must be global, apparently).

Thanks,
Reed Wilson

--
รง