create 'Ordering' type
This commit is contained in:
parent
77dfc8b182
commit
b0023afe8c
15 changed files with 158 additions and 117 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { makeCompareFn } from "../compare/dynamic.js";
|
||||
import { compareTypes } from "../compare/type.js";
|
||||
import { assignFn, UnifyError } from "../generics/generics.js";
|
||||
import { getInst, getType, newDynamic } from "../primitives/dynamic.js";
|
||||
import { Dynamic, Type } from "../primitives/primitive_types.js";
|
||||
import { getSymbol } from "../primitives/type.js";
|
||||
|
|
@ -26,7 +27,7 @@ export const module2Env = module => {
|
|||
try {
|
||||
return growEnv(typeDict)(dynamic);
|
||||
} catch (e) {
|
||||
console.log('warning:', e.message);
|
||||
console.log('skip:', e.message);
|
||||
return typeDict;
|
||||
}
|
||||
})(emptyDict(compareTypes))(module);
|
||||
|
|
@ -57,4 +58,37 @@ export const getFunctions = env => {
|
|||
}
|
||||
return types;
|
||||
})([])(types);
|
||||
};
|
||||
};
|
||||
|
||||
// return list of functions that can be called on 'dynamic'
|
||||
export const getEnabledFunctions = env => dynamic => {
|
||||
const allFunctions = getFunctions(env);
|
||||
const enabled = foldList(enabled => fun => {
|
||||
try {
|
||||
const outType = assignFn(getType(fun), getType(dynamic));
|
||||
return [...enabled, {fun, outType}];
|
||||
} catch (e) {
|
||||
if (!(e instanceof UnifyError)) {
|
||||
throw e;
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
})([])(allFunctions);
|
||||
return enabled;
|
||||
};
|
||||
|
||||
export const getCompatibleInputTypes = env => funType => {
|
||||
const allTypes = getTypes(env);
|
||||
const inTypes = foldSet(types => inType => {
|
||||
try {
|
||||
const outType = assignFn(funType, inType); // may throw
|
||||
return [...types, {inType, outType}];
|
||||
} catch (e) {
|
||||
if (!(e instanceof UnifyError)) {
|
||||
throw e;
|
||||
}
|
||||
return types;
|
||||
}
|
||||
})([])(allTypes);
|
||||
return inTypes;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue