From 106bd0bfdb9335363a7c582a53d6e4caa9e12290 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Fri, 16 May 2025 10:16:21 +0200 Subject: [PATCH] add function --- lib/generics/generics.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 => {