rewrite, simply and "power-up" unification

This commit is contained in:
Joeri Exelmans 2025-05-19 13:18:58 +02:00
parent d3515d39a5
commit dfe03eab6e
4 changed files with 211 additions and 175 deletions

View file

@ -1,8 +1,7 @@
import assert from "node:assert";
import { assignFn, assignFnSubstitutions, makeGeneric, unify, UnifyError } from "../lib/generics/generics.js";
import { assignFn, makeGeneric, unify, UnifyError } from "../lib/generics/generics.js";
import { getDefaultTypeParser } from "../lib/parser/type_parser.js";
import { prettyT } from "../lib/util/pretty.js";
import { TYPE_VARS, UNBOUND_SYMBOLS } from "../lib/primitives/typevars.js";
const mkType = getDefaultTypeParser();
@ -67,15 +66,12 @@ assert.throws(
UnifyError,
);
const [inType, inSubst, outType, outSubst] = assignFnSubstitutions(
mkType("Int -> Int"),
mkType("b"),
);
assert.equal(prettyT(inType), "Int");
assert.equal(prettyT(outType), "Int");
assert.equal(inSubst.size, 1);
assert.equal(prettyT(
inSubst.get(UNBOUND_SYMBOLS[1]) // b
), "Int")
assert.equal(outSubst.size, 0);
assert.throws(
() => {
unify(
mkType("((a -> (a -> Ordering)) -> {a})"),
mkType("([a] -> a)"),
)
},
UnifyError,
);