I am trying to implement the 'Bottom up' type inference algorithm which can be found in Generalizing Hindley-Milner Type Inference Algorithms
Page 6 explains how an implicit constraint is
t1
should be an instance of the type scheme that is obtained by generalizing typet2
with respect to the set of monomorphic type variablesM
However, on page 9, during the explanation of how to apply a substitution to an implicit constraints, I am told to apply a substitution to this set of monomorphic type variables. The problem is that if i have the substitution [t1 := t2 -> t3]
then M
is no longer a set of type variables.
What am I misunderstanding here?
I got in touch with the authors of the paper and when they told me the answer I did kick myself a bit:
The substitution function has the form
S : Substitution -> a -> a
so when applying this to a set of type variables then the result will be a set of type variables.So when applying
[t1 := t2 -> t3]
instead of replacing witht2 -> t3
I replace withftv(t2 -> t3)
aka[t2, t3]
(whereftv
is a function to get the free type variables in a type).