rename function + update index

This commit is contained in:
Joeri Exelmans 2025-05-19 13:23:36 +02:00
parent c1da60b71c
commit 28909d88b9
3 changed files with 10 additions and 4 deletions

6
index.d.ts vendored
View file

@ -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 {

View file

@ -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

View file

@ -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));