From 28909d88b997ce8ac6d1e33aece29f69f68e178c Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Mon, 19 May 2025 13:23:36 +0200 Subject: [PATCH] rename function + update index --- index.d.ts | 6 ++++++ lib/generics/generics.js | 6 +++--- lib/generics/low_level.js | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index d0c3575..6dc91c9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -348,6 +348,12 @@ export function sumType(typeParam: any): any; export function unify(fType: any, aType: any): any; +export function unifyLL(typeA: any, typeB: any): any; + +export function mergeUnifications(uniA: any, uniB: any): any; + +export function reduceUnification(uni: any): any; + export function zip(a: any, b: any): any; export namespace dict { diff --git a/lib/generics/generics.js b/lib/generics/generics.js index bab3de2..0f984e3 100644 --- a/lib/generics/generics.js +++ b/lib/generics/generics.js @@ -4,7 +4,7 @@ import { getSymbol } from "../primitives/type.js"; import { isTypeVar, TYPE_VARS, UNBOUND_SYMBOLS } from "../primitives/typevars.js"; import { symbolFunction } from "../structures/type_constructors.js"; import { prettyT } from '../util/pretty.js'; -import { reduceUnif, unifyLL } from "./low_level.js"; +import { reduceUnification, unifyLL } from "./low_level.js"; // helper for creating generic types // for instance, the type: @@ -41,7 +41,7 @@ export class NotAFunctionError extends Error {} export const unify = (fType, aType) => { [fType, aType] = recomputeTypeVars([fType, aType]); const unification = unifyLL(fType, aType); - const substitutions = reduceUnif(unification); + const substitutions = reduceUnification(unification); const uType = substitute(fType, // or aType, doesn't matter here substitutions); return recomputeTypeVars([uType])[0]; @@ -83,7 +83,7 @@ export const assignFn = (funType, paramType, skip=0) => { const unifInType1 = unifyLL(inType1, paramType1); // Step 4: Substitute typevars in output type - const substInType1 = reduceUnif(unifInType1); + const substInType1 = reduceUnification(unifInType1); const reducedOutType1 = substitute(outType1, substInType1); // Step 5: 'Normalize' output type diff --git a/lib/generics/low_level.js b/lib/generics/low_level.js index 76a3abd..414e8b9 100644 --- a/lib/generics/low_level.js +++ b/lib/generics/low_level.js @@ -130,7 +130,7 @@ export const reduce = (setOfTypes) => { // Reduce a unification to a mapping: {symbol => Type} // this mapping can then be used for substituting the typevars (=symbols) in a type by concrete types -export const reduceUnif = (unif) => { +export const reduceUnification = (unif) => { // console.log('b4 grown:', prettyU(unif)); const grown = transitivelyGrow(unif); // console.log('grown:', prettyU(grown));