add function
This commit is contained in:
parent
d75bf9f0f2
commit
106bd0bfdb
1 changed files with 8 additions and 2 deletions
|
|
@ -187,6 +187,12 @@ export const substitute = (type, substitutions, stack=[]) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const assignFn = (funType, paramType) => {
|
export const assignFn = (funType, paramType) => {
|
||||||
|
const [result] = assignFnSubstitutions(funType, paramType);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
// same as above, but also returns the substitutions that took place
|
||||||
|
export const assignFnSubstitutions = (funType, paramType) => {
|
||||||
if (getSymbol(funType) !== symbolFunction) {
|
if (getSymbol(funType) !== symbolFunction) {
|
||||||
throw new NotAFunctionError(`${prettyT(funType)} is not a function type!`);
|
throw new NotAFunctionError(`${prettyT(funType)} is not a function type!`);
|
||||||
}
|
}
|
||||||
|
|
@ -196,8 +202,8 @@ export const assignFn = (funType, paramType) => {
|
||||||
const {substitutions} = __unify(inType, paramType);
|
const {substitutions} = __unify(inType, paramType);
|
||||||
// console.log(substitutions, prettyT(outType));
|
// console.log(substitutions, prettyT(outType));
|
||||||
const substitutedFnType = substitute(outType, substitutions);
|
const substitutedFnType = substitute(outType, substitutions);
|
||||||
return recomputeTypeVars([substitutedFnType])[0];
|
return [recomputeTypeVars([substitutedFnType])[0], substitutions];
|
||||||
};
|
}
|
||||||
|
|
||||||
// Ensures that no type variables overlap
|
// Ensures that no type variables overlap
|
||||||
export const recomputeTypeVars = types => {
|
export const recomputeTypeVars = types => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue