First -yeah I read the papers,- it assumed, mostly, that generalization is 'good' because of the following example:
let f = [x -> x] in (f 3, f 'a')
If we wouldn't generalize the type of
f, it must be the identity on
char, which fails to typecheck. The only problem: The example is not general, it never happens. Functions which are polymorphic are usually written as definitions, and almost never occur in function bodies.
What does happen is that we want to know in local functions what argument types to expect, such that subsequently we can optimize better, i.e.:
Iflet g = [y -> print y] in g 3
int, then the generic function
Moreover, and this seems to be a source of 'features,' it is hard to generalize in the right order. In the example below, it should be derived that
zis a printable value.
Which fails, at the moment.f z = let x = [x -> x] in let g = [y -> print y] in g (f z)
Which leaves me with two choices. After thinking it through, I derived that linear order solving handles almost all cases, so that's no problem. So, get rid of generalizations is one choice, get rid of the bug the other. Guess I'll stick with generalizations, even if problematic. (Can only generalize over local variables, pattern matching and generalization are a hard mix.)
I guess I forgot an equality somewhere, or forgot assigning some variables monomorphic...
12/23/09: A substitution on a set of monomorphic variables is the set of free-variables after substitution.