diff --git a/lib/generics/generics.js b/lib/generics/generics.js index a722a1f..110b2d4 100644 --- a/lib/generics/generics.js +++ b/lib/generics/generics.js @@ -187,6 +187,12 @@ export const substitute = (type, substitutions, stack=[]) => { }; 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) { throw new NotAFunctionError(`${prettyT(funType)} is not a function type!`); } @@ -196,8 +202,8 @@ export const assignFn = (funType, paramType) => { const {substitutions} = __unify(inType, paramType); // console.log(substitutions, prettyT(outType)); const substitutedFnType = substitute(outType, substitutions); - return recomputeTypeVars([substitutedFnType])[0]; -}; + return [recomputeTypeVars([substitutedFnType])[0], substitutions]; +} // Ensures that no type variables overlap export const recomputeTypeVars = types => {