But this similar type has no problem: type 'a field = Int of int let a = Int 3 let b = Int (1 + 2) Both a and b receive the same generalized type. Why does the GADT style prevent this from occuring? On Mon, May 8, 2017 at 8:49 PM, Gabriel Scherer wrote: > This is the value restriction at work: only values are generalized > (often of the form "fun x -> ..."), and while (Int 3) is a value, (Int > (1 + 2)) is not. > > On Mon, May 8, 2017 at 11:32 AM, Reed Wilson wrote: > > 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 > > > > -- > > ç > -- ç