branching and very basic merging of slots
This commit is contained in:
parent
614e6c0fdb
commit
3978f7f835
32 changed files with 684 additions and 420 deletions
|
|
@ -1,39 +1,60 @@
|
|||
import { setType, typedFnType } from "./types.js";
|
||||
import { Bool, GenericType, Type } from "../primitives/types.js";
|
||||
import { fnType, setType } from "./types.js";
|
||||
import { Int } from "../primitives/types.js";
|
||||
import { makeGeneric } from "../generics/generics.js";
|
||||
|
||||
// 'normal' implementation
|
||||
const emptySet = new Set();
|
||||
const emptySetType = makeGeneric(a => setType(a));
|
||||
const has = set => elem => set.has(elem);
|
||||
const add = set => elem => new Set([...set, elem]);
|
||||
import createRBTree from "functional-red-black-tree";
|
||||
import { inspect } from "node:util";
|
||||
|
||||
export class RBTreeWrapper {
|
||||
constructor(tree) {
|
||||
this.tree = tree;
|
||||
}
|
||||
[inspect.custom](depth, options, inspect) {
|
||||
const entries = [];
|
||||
this.tree.forEach((key,val) => {entries.push(`${inspect(key)} => ${inspect(val)}`);});
|
||||
return `RBTree(${this.tree.length}) {${entries.join(', ')}}`;
|
||||
}
|
||||
}
|
||||
|
||||
// (a -> a -> Int) -> Set(a)
|
||||
export const emptySet = compareFn => new RBTreeWrapper(createRBTree((x, y) => compareFn(x)(y)));
|
||||
|
||||
// const emptySetType = makeGeneric(a => fnType(fnType(a)(fnType(a)(Int)))(setType(a)));
|
||||
|
||||
export const has = set => key => set.tree.get(key) === true;
|
||||
export const add = set => key => set.tree.get(key) === true ? set : new RBTreeWrapper(set.tree.insert(key, true));
|
||||
export const remove = set => key => new RBTreeWrapper(set.tree.remove(key));
|
||||
|
||||
export const forEach = set => fn => {
|
||||
set.tree.forEach(key => { fn(key); });
|
||||
};
|
||||
|
||||
export const ModuleSet = {l:[
|
||||
// Type -> Type
|
||||
...typedFnType(setType, fnType =>
|
||||
fnType
|
||||
/* in */ (Type)
|
||||
/* out */ (Type)
|
||||
),
|
||||
// // Type -> Type
|
||||
// ...typedFnType(setType, fnType =>
|
||||
// fnType
|
||||
// /* in */ (Type)
|
||||
// /* out */ (Type)
|
||||
// ),
|
||||
|
||||
{i: emptySet , t: emptySetType},
|
||||
{i: emptySetType, t: GenericType },
|
||||
// {i: emptySet , t: emptySetType},
|
||||
// {i: emptySetType, t: GenericType },
|
||||
|
||||
...typedFnType(has, fnType =>
|
||||
makeGeneric(a =>
|
||||
fnType
|
||||
/* in */ (setType(a))
|
||||
/* out */ (fnType
|
||||
/* in */ (a)
|
||||
/* out */ (Bool)
|
||||
)), GenericType),
|
||||
// ...typedFnType(has, fnType =>
|
||||
// makeGeneric(a =>
|
||||
// fnType
|
||||
// /* in */ (setType(a))
|
||||
// /* out */ (fnType
|
||||
// /* in */ (a)
|
||||
// /* out */ (Bool)
|
||||
// )), GenericType),
|
||||
|
||||
...typedFnType(add, fnType =>
|
||||
makeGeneric(a =>
|
||||
fnType
|
||||
/* in */ (setType(a))
|
||||
/* out */ (fnType
|
||||
/* in */ (a)
|
||||
/* out */ (setType(a))
|
||||
)), GenericType),
|
||||
// ...typedFnType(add, fnType =>
|
||||
// makeGeneric(a =>
|
||||
// fnType
|
||||
// /* in */ (setType(a))
|
||||
// /* out */ (fnType
|
||||
// /* in */ (a)
|
||||
// /* out */ (setType(a))
|
||||
// )), GenericType),
|
||||
]};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue