small changes

This commit is contained in:
Joeri Exelmans 2025-05-08 23:35:34 +02:00
parent 4c394441b0
commit 34d06aa82a
3 changed files with 23 additions and 6 deletions

View file

@ -3,17 +3,25 @@ import { ModuleStd } from "../lib/stdlib.js";
import { emptyDict, get, set } from "../lib/structures/dict.js"; import { emptyDict, get, set } from "../lib/structures/dict.js";
import { emptySet, add } from "../lib/structures/set.js"; import { emptySet, add } from "../lib/structures/set.js";
import { makeCompareFn } from "../lib/compare/dynamic.js" import { makeCompareFn } from "../lib/compare/dynamic.js"
import { Type } from "../lib/primitives/primitive_types.js";
// console.log(ModuleStd); console.log(ModuleStd);
const addEntry = dict => i => t => {
const setOfInstances = get(dict)(t) || emptySet(makeCompareFn(t));
return set(dict)(t)(add(setOfInstances)(i));
}
const typeDict = ModuleStd.reduce((typeDict, {i, t}) => { const typeDict = ModuleStd.reduce((typeDict, {i, t}) => {
try { try {
const instances = get(typeDict)(t) || emptySet(makeCompareFn(t)); // add instance to type:
return set(typeDict)(t)(add(instances)(i)); return addEntry(
addEntry(typeDict)(i)(t)
)(t)(Type);
} catch (e) { } catch (e) {
console.log('warning:',e.message); console.log('warning:',e.message);
return typeDict; return typeDict;
} }
}, emptyDict(compareTypes)); }, emptyDict(compareTypes));
console.log(typeDict); console.log(typeDict);

View file

@ -1,10 +1,11 @@
import { getDefaultTypeParser } from "../parser/type_parser.js"; import { getDefaultTypeParser } from "../parser/type_parser.js";
import { addDouble, eqDouble, mulDouble } from "./double.js"; import { addDouble, eqDouble, mulDouble } from "./double.js";
import { newDynamic } from "./dynamic.js";
const mkType = getDefaultTypeParser(); const mkType = getDefaultTypeParser();
export const ModuleDouble = [ export const ModuleDouble = [
{ i: addDouble, t: mkType("Double -> Double -> Double") }, newDynamic(addDouble)(mkType("Double -> Double -> Double")),
{ i: mulDouble, t: mkType("Double -> Double -> Double") }, { i: mulDouble, t: mkType("Double -> Double -> Double") },
{ i: eqDouble, t: mkType("Double -> Double -> Bool") }, { i: eqDouble, t: mkType("Double -> Double -> Bool") },
]; ];

View file

@ -1,6 +1,14 @@
import { inspect } from "node:util";
import { assignFn } from "../generics/generics.js"; import { assignFn } from "../generics/generics.js";
export const newDynamic = i => t => ({i, t}); function inspectDynamic(_depth, options, inspect) {
return `${inspect(this.i, options)} :: ${inspect(this.t, options)}`;
}
export const newDynamic = i => t => ({
i, t,
[inspect.custom]: inspectDynamic,
});
export const getInst = lnk => lnk.i; export const getInst = lnk => lnk.i;
export const getType = lnk => lnk.t; export const getType = lnk => lnk.t;