turn one example into a test + fix bug in type variable substition function
This commit is contained in:
parent
a664ddac8a
commit
35d682429b
4 changed files with 148 additions and 102 deletions
|
|
@ -163,17 +163,24 @@ export const unify = (fType, aType) => {
|
|||
|
||||
export const substitute = (type, substitutions, stack=[]) => {
|
||||
// console.log('substitute...', {type, substitutions, stack});
|
||||
return substitutions.get(getSymbol(type))
|
||||
|| {
|
||||
const found = substitutions.get(getSymbol(type));
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
return {
|
||||
symbol: getSymbol(type),
|
||||
params: type.params.map(getParam => parent => {
|
||||
const param = getParam(stack.length);
|
||||
return stack[param]
|
||||
|| substitute(param, substitutions, [...stack, parent]);
|
||||
const param = getParam(parent);
|
||||
if (stack.includes(param)) {
|
||||
// param points back up - that's ok - means we don't have to recurse
|
||||
return param;
|
||||
}
|
||||
return substitute(param, substitutions, [...stack, parent]);
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
export const assignFn = (funType, paramType) => {
|
||||
[funType, paramType] = recomputeTypeVars([funType, paramType]);
|
||||
// console.log(prettyT(funType), prettyT(paramType));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue