small changes
This commit is contained in:
parent
4c394441b0
commit
34d06aa82a
3 changed files with 23 additions and 6 deletions
|
|
@ -3,13 +3,21 @@ 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;
|
||||||
|
|
|
||||||
|
|
@ -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") },
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue