type inferencing "unifying" operation is now bi-directional + begin writing generic version of "unifying" operation (that should work on all types)

This commit is contained in:
Joeri Exelmans 2025-03-20 19:59:24 +01:00
parent c5ac55b0ff
commit 33c156fc5c
5 changed files with 148 additions and 9 deletions

View file

@ -0,0 +1,38 @@
import { makeGeneric } from "../generics/generics";
import { Type, typedFnType } from "../metacircular";
import { Bool, Byte, Char, Double, Int } from "../primitives/symbols";
import { deepEqual } from "../util";
import { eqDictType } from "./eq_type";
export const getEq = numDict => numDict.eq;
export const ModuleEq = {l:[
...typedFnType(eqDictType, fnType => fnType({in: Type, out: Type})),
...typedFnType(getEq, fnType => makeGeneric(a =>
fnType({
in: eqDictType(a),
out: fnType({
in: a,
out: fnType({
in: a,
out: Bool,
}),
}),
}))),
]};
// all our data (and types) are encoded such that we can test equality the same way:
const eq = x => y => deepEqual(x,y);
const EqDict = {eq};
export const EqInstances = new Map([
[Int, EqDict],
[Bool, EqDict],
[Double, EqDict],
[Byte, EqDict],
[Char, EqDict],
[Type, EqDict],
]);