rewrite, simply and "power-up" unification
This commit is contained in:
parent
d3515d39a5
commit
dfe03eab6e
4 changed files with 211 additions and 175 deletions
|
|
@ -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,
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue