create 'Ordering' type
This commit is contained in:
parent
77dfc8b182
commit
b0023afe8c
15 changed files with 158 additions and 117 deletions
|
|
@ -1,9 +1,18 @@
|
||||||
|
|
||||||
import { module2Env } from "../lib/environment/env.js";
|
import { module2Env } from "../lib/environment/env.js";
|
||||||
|
import { newDynamic } from "../lib/primitives/dynamic.js";
|
||||||
import { Dynamic } from "../lib/primitives/primitive_types.js";
|
import { Dynamic } from "../lib/primitives/primitive_types.js";
|
||||||
|
import { TYPE_VARS } from "../lib/primitives/typevars.js";
|
||||||
import { ModuleStd } from "../lib/stdlib.js";
|
import { ModuleStd } from "../lib/stdlib.js";
|
||||||
import { listInstances } from "./prompt/prompt.js";
|
import { emptyList } from "../lib/structures/list.js";
|
||||||
|
import { lsType } from "../lib/structures/type_constructors.types.js";
|
||||||
|
import { listInstances, transform } from "./prompt/prompt.js";
|
||||||
|
|
||||||
const typeDict = module2Env(ModuleStd);
|
const env = module2Env(ModuleStd);
|
||||||
|
|
||||||
await listInstances(typeDict, Dynamic);
|
await listInstances(env, Dynamic);
|
||||||
|
|
||||||
|
await transform(
|
||||||
|
env,
|
||||||
|
newDynamic(emptyList)(lsType(_ => TYPE_VARS[0])),
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,9 @@
|
||||||
import { number, select } from "@inquirer/prompts";
|
import { number, select } from "@inquirer/prompts";
|
||||||
|
|
||||||
import { makeCompareFn } from "../../lib/compare/dynamic.js";
|
import { getCompatibleInputTypes, getEnabledFunctions, getInstances, growEnv } from "../../lib/environment/env.js";
|
||||||
import { getFunctions, getInstances, getTypes, growEnv } from "../../lib/environment/env.js";
|
|
||||||
import { assignFn } from "../../lib/generics/generics.js";
|
|
||||||
import { getInst, getType, newDynamic } from "../../lib/primitives/dynamic.js";
|
import { getInst, getType, newDynamic } from "../../lib/primitives/dynamic.js";
|
||||||
import { Bool, Double, Int, SymbolDynamic, Type, UUID } from "../../lib/primitives/primitive_types.js";
|
import { Bool, Double, Int, SymbolDynamic, Type, UUID } from "../../lib/primitives/primitive_types.js";
|
||||||
import { eqType, getSymbol } from "../../lib/primitives/type.js";
|
import { eqType, getSymbol } from "../../lib/primitives/type.js";
|
||||||
import { ModuleStd } from "../../lib/stdlib.js";
|
|
||||||
import { fold as foldList } from "../../lib/structures/list.js";
|
|
||||||
import { fold as foldSet } from "../../lib/structures/set.js";
|
import { fold as foldSet } from "../../lib/structures/set.js";
|
||||||
import { symbolFunction } from "../../lib/structures/type_constructors.js";
|
import { symbolFunction } from "../../lib/structures/type_constructors.js";
|
||||||
import { pretty, prettyT } from "../../lib/util/pretty.js";
|
import { pretty, prettyT } from "../../lib/util/pretty.js";
|
||||||
|
|
@ -168,20 +164,10 @@ const createInstance = async (type) => {
|
||||||
console.log("no prompt handler for creating new", prettyT(type));
|
console.log("no prompt handler for creating new", prettyT(type));
|
||||||
};
|
};
|
||||||
|
|
||||||
const transform = async (env, dynamic) => {
|
export const transform = async (env, dynamic) => {
|
||||||
const allFunctions = getFunctions(env);
|
const enabled = getEnabledFunctions(env)(dynamic);
|
||||||
const enabled = foldList(enabled => fun => {
|
|
||||||
try {
|
|
||||||
const outType = assignFn(getType(fun), getType(dynamic));
|
|
||||||
return [...enabled, {fun, outType}];
|
|
||||||
} catch (e) {
|
|
||||||
// console.log('warning:', e);
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
})([])(allFunctions);
|
|
||||||
|
|
||||||
const choice = await select({
|
const choice = await select({
|
||||||
message: `select:`,
|
message: `select transformation:`,
|
||||||
choices: [
|
choices: [
|
||||||
"(go back)",
|
"(go back)",
|
||||||
...enabled.map(({fun, outType}) => ({
|
...enabled.map(({fun, outType}) => ({
|
||||||
|
|
@ -203,18 +189,7 @@ const transform = async (env, dynamic) => {
|
||||||
|
|
||||||
const call = async (env, funDynamic) => {
|
const call = async (env, funDynamic) => {
|
||||||
const funType = getType(funDynamic);
|
const funType = getType(funDynamic);
|
||||||
const allTypes = getTypes(env);
|
const inTypes = getCompatibleInputTypes(env)(funType);
|
||||||
|
|
||||||
// compatible input types
|
|
||||||
const inTypes = foldSet(types => inType => {
|
|
||||||
try {
|
|
||||||
const outType = assignFn(funType, inType); // may throw
|
|
||||||
return [...types, {inType, outType}];
|
|
||||||
} catch (e) {
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
})([])(allTypes);
|
|
||||||
|
|
||||||
const choice = inTypes.length === 1
|
const choice = inTypes.length === 1
|
||||||
? inTypes[0]
|
? inTypes[0]
|
||||||
: await select({
|
: await select({
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import { getInst, getType } from "../primitives/dynamic.js";
|
import { getInst, getType } from "../primitives/dynamic.js";
|
||||||
import { SymbolBool, SymbolBottom, SymbolByte, SymbolChar, SymbolDouble, SymbolDynamic, SymbolInt, SymbolUUID, SymbolType, SymbolUnit } from "../primitives/primitive_types.js";
|
import { SymbolBool, SymbolBottom, SymbolByte, SymbolChar, SymbolDouble, SymbolDynamic, SymbolInt, SymbolUUID, SymbolType, SymbolUnit, SymbolOrdering } from "../primitives/primitive_types.js";
|
||||||
import { UNBOUND_SYMBOLS } from "../primitives/typevars.js";
|
import { UNBOUND_SYMBOLS } from "../primitives/typevars.js";
|
||||||
import { symbolDict, symbolFunction, symbolList, symbolProduct, symbolSet, symbolSum } from "../structures/type_constructors.js";
|
import { symbolDict, symbolFunction, symbolList, symbolProduct, symbolSet, symbolSum } from "../structures/type_constructors.js";
|
||||||
import { prettyT } from "../util/pretty.js";
|
import { prettyT } from "../util/pretty.js";
|
||||||
import { compareBools, compareNumbers, compareStrings, compareSymbols, compareUnits } from "./primitives.js";
|
import { compareBools, compareDoubles, compareOrderings, compareStrings, compareSymbols, compareUnits } from "./primitives.js";
|
||||||
import { compareDicts, compareFunctions, compareLists, compareProducts, compareSets, compareSums } from "./structures.js";
|
import { compareDicts, compareFunctions, compareLists, compareProducts, compareSets, compareSums } from "./structures.js";
|
||||||
import { compareTypes } from "./type.js";
|
import { compareTypes } from "./type.js";
|
||||||
|
|
||||||
|
|
@ -14,25 +14,26 @@ export const compareDynamic = x => y =>
|
||||||
const cannotCompareTypeVarInstances = _ => _ => { throw new Error("Cannot compare instance of type variables"); }
|
const cannotCompareTypeVarInstances = _ => _ => { throw new Error("Cannot compare instance of type variables"); }
|
||||||
|
|
||||||
const typeSymbolToCmp = new Map([
|
const typeSymbolToCmp = new Map([
|
||||||
[SymbolInt , compareNumbers],
|
[SymbolInt , compareDoubles ],
|
||||||
[SymbolBool , compareBools],
|
[SymbolBool , compareBools ],
|
||||||
[SymbolDouble , compareNumbers],
|
[SymbolDouble , compareDoubles ],
|
||||||
[SymbolByte , compareNumbers],
|
[SymbolByte , compareDoubles ],
|
||||||
[SymbolChar , compareStrings],
|
[SymbolChar , compareStrings ],
|
||||||
[SymbolUnit , compareUnits],
|
[SymbolUnit , compareUnits ],
|
||||||
[SymbolBottom , _ => _ => { throw new Error("Bottom!"); }],
|
[SymbolBottom , _ => _ => { throw new Error("Bottom!"); }],
|
||||||
[SymbolUUID , compareSymbols],
|
[SymbolUUID , compareSymbols ],
|
||||||
// [SymbolGenericType, ?] TODO
|
// [SymbolGenericType, ?] TODO
|
||||||
[SymbolType , compareTypes],
|
[SymbolType , compareTypes ],
|
||||||
[SymbolDynamic, compareDynamic],
|
[SymbolDynamic , compareDynamic ],
|
||||||
|
[SymbolOrdering, compareOrderings],
|
||||||
|
|
||||||
// these functions take extra comparison callbacks:
|
// these functions take extra comparison callbacks:
|
||||||
[symbolFunction, compareFunctions],
|
[symbolFunction, compareFunctions],
|
||||||
[symbolSum , compareSums],
|
[symbolSum , compareSums ],
|
||||||
[symbolProduct , compareProducts],
|
[symbolProduct , compareProducts ],
|
||||||
[symbolList , compareLists],
|
[symbolList , compareLists ],
|
||||||
[symbolSet , compareSets],
|
[symbolSet , compareSets ],
|
||||||
[symbolDict , compareDicts],
|
[symbolDict , compareDicts ],
|
||||||
|
|
||||||
// even though we cannot compare typevar instances,
|
// even though we cannot compare typevar instances,
|
||||||
// we still need to give a function or shit will break
|
// we still need to give a function or shit will break
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
||||||
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
import { compareDynamic, makeCompareFn } from "./dynamic.js";
|
import { compareDynamic, makeCompareFn } from "./dynamic.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleCompareDynamic = [
|
export const ModuleCompareDynamic = [
|
||||||
newDynamic(makeCompareFn )(mkType("Type -> a -> a -> Int")),
|
newDynamic(makeCompareFn )(mkType("Type -> a -> a -> Ordering")),
|
||||||
newDynamic(compareDynamic)(mkType("Dynamic -> Dynamic -> Int")),
|
newDynamic(compareDynamic)(mkType("Dynamic -> Dynamic -> Ordering")),
|
||||||
];
|
];
|
||||||
|
|
@ -1,18 +1,25 @@
|
||||||
// Total ordering of primitive types
|
// Total ordering of primitive types
|
||||||
|
|
||||||
export const compareNumbers = x => y => {
|
export const compareInts = x => y => {
|
||||||
|
if (typeof(x) !== 'bigint' || typeof(y) !== 'bigint') {
|
||||||
|
throw new Error(`was only meant to compare bigints! got ${x} and ${y}`);
|
||||||
|
}
|
||||||
|
return (x < y) ? -1 : (x > y) ? 1 : 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const compareDoubles = x => y => {
|
||||||
if (typeof(x) !== 'number' || typeof(y) !== 'number') {
|
if (typeof(x) !== 'number' || typeof(y) !== 'number') {
|
||||||
throw new Error(`was only meant to compare numbers! got ${x} and ${y}`);
|
throw new Error(`was only meant to compare numbers! got ${x} and ${y}`);
|
||||||
}
|
}
|
||||||
return (x < y) ? -1 : (x > y) ? 1 : 0;
|
return (x < y) ? -1 : (x > y) ? 1 : 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const compareStrings = x => y => {
|
export const compareStrings = x => y => {
|
||||||
if (typeof(x) !== 'string' || typeof(y) !== 'string') {
|
if (typeof(x) !== 'string' || typeof(y) !== 'string') {
|
||||||
throw new Error(`was only meant to compare strings! got ${x} and ${y}`);
|
throw new Error(`was only meant to compare strings! got ${x} and ${y}`);
|
||||||
}
|
}
|
||||||
return (x < y) ? -1 : (x > y) ? 1 : 0;
|
return (x < y) ? -1 : (x > y) ? 1 : 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const compareBools = x => y => {
|
export const compareBools = x => y => {
|
||||||
if (typeof(x) !== 'boolean' || typeof(y) !== 'boolean') {
|
if (typeof(x) !== 'boolean' || typeof(y) !== 'boolean') {
|
||||||
|
|
@ -26,3 +33,5 @@ export const compareUnits = _ => _ => 0;
|
||||||
|
|
||||||
// Symbols are encoded as strings
|
// Symbols are encoded as strings
|
||||||
export const compareSymbols = a => b => compareStrings(a)(b);
|
export const compareSymbols = a => b => compareStrings(a)(b);
|
||||||
|
|
||||||
|
export const compareOrderings = a => b => compareDoubles(a)(b);
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
||||||
import { newDynamic } from "../primitives/dynamic.js";
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
import { compareBools, compareNumbers, compareSymbols, compareUnits } from "./primitives.js";
|
import { compareBools, compareDoubles, compareInts, compareOrderings, compareSymbols, compareUnits } from "./primitives.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleComparePrimitives = [
|
export const ModuleComparePrimitives = [
|
||||||
newDynamic(compareNumbers)(mkType("Double -> Double -> Int")),
|
newDynamic(compareInts )(mkType("Int -> Int -> Ordering" )),
|
||||||
newDynamic(compareBools )(mkType("Bool -> Bool -> Int")),
|
newDynamic(compareDoubles )(mkType("Double -> Double -> Ordering" )),
|
||||||
newDynamic(compareUnits )(mkType("Unit -> Unit -> Int")),
|
newDynamic(compareBools )(mkType("Bool -> Bool -> Ordering" )),
|
||||||
newDynamic(compareSymbols)(mkType("UUID -> UUID -> Int")),
|
newDynamic(compareUnits )(mkType("Unit -> Unit -> Ordering" )),
|
||||||
|
newDynamic(compareSymbols )(mkType("UUID -> UUID -> Ordering" )),
|
||||||
|
newDynamic(compareOrderings)(mkType("Ordering -> Ordering -> Ordering")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// Total ordering of composed types
|
// Total ordering of composed types
|
||||||
|
|
||||||
import { compareNumbers, compareStrings } from "./primitives.js"
|
import { compareDoubles, compareStrings } from "./primitives.js"
|
||||||
import { get, length as lengthLs } from "../structures/list.js";
|
import { get, length as lengthLs } from "../structures/list.js";
|
||||||
import { read as readSet, length as lengthSet, first as firstSet } from "../structures/set.js";
|
import { read as readSet, length as lengthSet, first as firstSet } from "../structures/set.js";
|
||||||
import { read as readDict, length as lengthDict, first as firstDict } from "../structures/dict.js";
|
import { read as readDict, length as lengthDict, first as firstDict } from "../structures/dict.js";
|
||||||
|
|
@ -13,7 +13,7 @@ export const compareFunctions = _compareInput => _compareOutput => x => y => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const compareLists = compareElems => x => y => {
|
export const compareLists = compareElems => x => y => {
|
||||||
return compareNumbers(lengthLs(x))(lengthLs(y))
|
return compareDoubles(lengthLs(x))(lengthLs(y))
|
||||||
|| (() => {
|
|| (() => {
|
||||||
for (let i=0; i<lengthLs(x); i++) {
|
for (let i=0; i<lengthLs(x); i++) {
|
||||||
const elemCmp = compareElems(get(x)(i))(get(y)(i));
|
const elemCmp = compareElems(get(x)(i))(get(y)(i));
|
||||||
|
|
@ -50,7 +50,7 @@ export const compareSums = compareLeft => compareRight => x => y => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const compareSets = compareElems => x => y => {
|
export const compareSets = compareElems => x => y => {
|
||||||
return compareNumbers(lengthSet(x))(lengthSet(y))
|
return compareDoubles(lengthSet(x))(lengthSet(y))
|
||||||
|| (() => {
|
|| (() => {
|
||||||
// sets have same size -> iterate over both sets and compare their elements pairwise
|
// sets have same size -> iterate over both sets and compare their elements pairwise
|
||||||
// because of the underlying red-black tree, iteration happens in ordered fashion
|
// because of the underlying red-black tree, iteration happens in ordered fashion
|
||||||
|
|
@ -71,7 +71,7 @@ export const compareSets = compareElems => x => y => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const compareDicts = compareKeys => compareValues => x => y => {
|
export const compareDicts = compareKeys => compareValues => x => y => {
|
||||||
return compareNumbers(lengthDict(x))(lengthDict(y))
|
return compareDoubles(lengthDict(x))(lengthDict(y))
|
||||||
|| (() => {
|
|| (() => {
|
||||||
// dicts have same size -> iterate over both and compare their entries pairwise
|
// dicts have same size -> iterate over both and compare their entries pairwise
|
||||||
// because of the underlying red-black tree, iteration happens in ordered fashion
|
// because of the underlying red-black tree, iteration happens in ordered fashion
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ import { compareDicts, compareLists, compareProducts, compareSets, compareSums }
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleCompareStructures = [
|
export const ModuleCompareStructures = [
|
||||||
newDynamic(compareLists)(mkType("(a -> a -> Int) -> [a] -> [a] -> Int")),
|
newDynamic(compareLists)(mkType("(a -> a -> Ordering) -> [a] -> [a] -> Ordering")),
|
||||||
|
|
||||||
newDynamic(compareProducts)(mkType("(a -> a -> Int) -> (b -> b -> Int) -> (a*b) -> (a*b) -> Int")),
|
newDynamic(compareProducts)(mkType("(a -> a -> Ordering) -> (b -> b -> Ordering) -> (a*b) -> (a*b) -> Ordering")),
|
||||||
|
|
||||||
newDynamic(compareSums)(mkType("(a -> a -> Int) -> (b -> b -> Int) -> (a+b) -> (a+b) -> Int")),
|
newDynamic(compareSums)(mkType("(a -> a -> Ordering) -> (b -> b -> Ordering) -> (a+b) -> (a+b) -> Ordering")),
|
||||||
|
|
||||||
newDynamic(compareSets)(mkType("(a -> a -> Int) -> {a} -> {a} -> Int")),
|
newDynamic(compareSets)(mkType("(a -> a -> Ordering) -> {a} -> {a} -> Ordering")),
|
||||||
|
|
||||||
newDynamic(compareDicts)(mkType("(a -> a -> Int) -> (b -> b-> Int) -> (a => b) -> (a => b) -> Int"))
|
newDynamic(compareDicts)(mkType("(a -> a -> Ordering) -> (b -> b-> Ordering) -> (a => b) -> (a => b) -> Ordering"))
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { getParams, getSymbol } from "../primitives/type.js";
|
import { getParams, getSymbol } from "../primitives/type.js";
|
||||||
import { compareBools, compareNumbers, compareSymbols } from "./primitives.js";
|
import { compareBools, compareDoubles, compareSymbols } from "./primitives.js";
|
||||||
import { compareLists } from "./structures.js";
|
import { compareLists } from "./structures.js";
|
||||||
|
|
||||||
const __compareTypes = state => typeX => typeY => {
|
const __compareTypes = state => typeX => typeY => {
|
||||||
|
|
@ -20,7 +20,7 @@ const __compareTypes = state => typeX => typeY => {
|
||||||
// both sub-types have been visited already in an enclosing call
|
// both sub-types have been visited already in an enclosing call
|
||||||
// if they were being compared in the same enclosing call, we assume they are equal!
|
// if they were being compared in the same enclosing call, we assume they are equal!
|
||||||
// (we cannot compare them, that would result in endless recursion)
|
// (we cannot compare them, that would result in endless recursion)
|
||||||
return compareNumbers(state.comparing.get(pX))(pY);
|
return compareDoubles(state.comparing.get(pX))(pY);
|
||||||
}
|
}
|
||||||
// none have been visited -> recursively compare
|
// none have been visited -> recursively compare
|
||||||
return __compareTypes(state)(pX)(pY);
|
return __compareTypes(state)(pX)(pY);
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@ import { compareTypes } from "./type.js";
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleCompareTypes = [
|
export const ModuleCompareTypes = [
|
||||||
newDynamic(compareTypes)(mkType("Type -> Type -> Int")),
|
newDynamic(compareTypes)(mkType("Type -> Type -> Ordering")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { makeCompareFn } from "../compare/dynamic.js";
|
import { makeCompareFn } from "../compare/dynamic.js";
|
||||||
import { compareTypes } from "../compare/type.js";
|
import { compareTypes } from "../compare/type.js";
|
||||||
|
import { assignFn, UnifyError } from "../generics/generics.js";
|
||||||
import { getInst, getType, newDynamic } from "../primitives/dynamic.js";
|
import { getInst, getType, newDynamic } from "../primitives/dynamic.js";
|
||||||
import { Dynamic, Type } from "../primitives/primitive_types.js";
|
import { Dynamic, Type } from "../primitives/primitive_types.js";
|
||||||
import { getSymbol } from "../primitives/type.js";
|
import { getSymbol } from "../primitives/type.js";
|
||||||
|
|
@ -26,7 +27,7 @@ export const module2Env = module => {
|
||||||
try {
|
try {
|
||||||
return growEnv(typeDict)(dynamic);
|
return growEnv(typeDict)(dynamic);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('warning:', e.message);
|
console.log('skip:', e.message);
|
||||||
return typeDict;
|
return typeDict;
|
||||||
}
|
}
|
||||||
})(emptyDict(compareTypes))(module);
|
})(emptyDict(compareTypes))(module);
|
||||||
|
|
@ -58,3 +59,36 @@ export const getFunctions = env => {
|
||||||
return types;
|
return types;
|
||||||
})([])(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;
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// A simple, hacked-together recursive parser for types.
|
// A simple, hacked-together recursive parser for types.
|
||||||
|
|
||||||
import { Bool, Char, Double, Int, UUID, Type, Unit } from "../primitives/primitive_types.js";
|
import { Bool, Char, Double, Int, UUID, Type, Unit, Ordering } from "../primitives/primitive_types.js";
|
||||||
import { Dynamic } from "../primitives/primitive_types.js";
|
import { Dynamic } from "../primitives/primitive_types.js";
|
||||||
import { getHumanReadableName } from "../primitives/symbol.js";
|
import { getHumanReadableName } from "../primitives/symbol.js";
|
||||||
import { getSymbol } from "../primitives/type.js";
|
import { getSymbol } from "../primitives/type.js";
|
||||||
|
|
@ -21,16 +21,17 @@ export const makeTypeParser = ({
|
||||||
extraInfixOperators=[],
|
extraInfixOperators=[],
|
||||||
}) => {
|
}) => {
|
||||||
const primitives = new Map([
|
const primitives = new Map([
|
||||||
['Int', Int],
|
['Int' , Int ],
|
||||||
['Double', Double],
|
['Double' , Double ],
|
||||||
['Bool', Bool],
|
['Bool' , Bool ],
|
||||||
['Char', Char],
|
['Char' , Char ],
|
||||||
['String', lsType(_ => Char)],
|
['String' , lsType(_ => Char) ],
|
||||||
['Module', lsType(_ => Dynamic)],
|
['Module' , lsType(_ => Dynamic)],
|
||||||
['Unit', Unit],
|
['Unit' , Unit ],
|
||||||
['Type', Type],
|
['Type' , Type ],
|
||||||
['Dynamic', Dynamic],
|
['Dynamic' , Dynamic ],
|
||||||
['UUID', UUID],
|
['UUID' , UUID ],
|
||||||
|
['Ordering', Ordering ],
|
||||||
|
|
||||||
...TYPE_VARS.map(type => [getHumanReadableName(getSymbol(type)), type]),
|
...TYPE_VARS.map(type => [getHumanReadableName(getSymbol(type)), type]),
|
||||||
|
|
||||||
|
|
@ -38,21 +39,21 @@ export const makeTypeParser = ({
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const bracketOperators = new Map([
|
const bracketOperators = new Map([
|
||||||
['(', [')', null]],
|
['(', [')', null ]],
|
||||||
['[', [']', lsType]],
|
['[', [']', lsType ]],
|
||||||
['{', ['}', setType]],
|
['{', ['}', setType]],
|
||||||
|
|
||||||
...extraBracketOperators,
|
...extraBracketOperators,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const infixOperators = new Map([
|
const infixOperators = new Map([
|
||||||
['+', sumType],
|
['+' , sumType ],
|
||||||
['|', sumType],
|
['|' , sumType ],
|
||||||
['⨯', prodType],
|
['⨯' , prodType],
|
||||||
['*', prodType],
|
['*' , prodType],
|
||||||
['→', fnType],
|
['→' , fnType ],
|
||||||
['->', fnType],
|
['->', fnType ],
|
||||||
['⇒', dictType],
|
['⇒' , dictType],
|
||||||
['=>', dictType],
|
['=>', dictType],
|
||||||
|
|
||||||
...extraInfixOperators,
|
...extraInfixOperators,
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ export const SymbolType = "Type__fdbea309d66f49b483b0dd4ceb785f7d";
|
||||||
export const SymbolTop = "⊤__38709c3c0039468782103256d4730d1f";
|
export const SymbolTop = "⊤__38709c3c0039468782103256d4730d1f";
|
||||||
export const SymbolDynamic = "Dynamic__3c16c415dba94228ada37dc9d446f54f";
|
export const SymbolDynamic = "Dynamic__3c16c415dba94228ada37dc9d446f54f";
|
||||||
|
|
||||||
|
|
||||||
|
export const SymbolOrdering = "Ordering__a11578cc83352023f16ffa2d060c52c2";
|
||||||
|
|
||||||
export const Int = makeTypeConstructor(SymbolInt)(0);
|
export const Int = makeTypeConstructor(SymbolInt)(0);
|
||||||
export const Bool = makeTypeConstructor(SymbolBool)(0);
|
export const Bool = makeTypeConstructor(SymbolBool)(0);
|
||||||
export const Double = makeTypeConstructor(SymbolDouble)(0);
|
export const Double = makeTypeConstructor(SymbolDouble)(0);
|
||||||
|
|
@ -35,3 +38,5 @@ export const Type = makeTypeConstructor(SymbolType)(0);
|
||||||
export const Top = makeTypeConstructor(SymbolTop)(0);// A type-link, connecting a value to its Type.
|
export const Top = makeTypeConstructor(SymbolTop)(0);// A type-link, connecting a value to its Type.
|
||||||
|
|
||||||
export const Dynamic = makeTypeConstructor(SymbolDynamic)(0);
|
export const Dynamic = makeTypeConstructor(SymbolDynamic)(0);
|
||||||
|
|
||||||
|
export const Ordering = makeTypeConstructor(SymbolOrdering)(0);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { newDynamic } from "./dynamic.js";
|
import { newDynamic } from "./dynamic.js";
|
||||||
import { SymbolInt, UUID, SymbolBool, SymbolDouble, SymbolByte, SymbolChar, SymbolUnit, SymbolBottom, SymbolUUID, SymbolType, SymbolTop, Type, Int, Bool, Double, Byte, Char, Unit, Bottom, Top, SymbolDynamic, Dynamic } from "./primitive_types.js";
|
import { SymbolInt, UUID, SymbolBool, SymbolDouble, SymbolByte, SymbolChar, SymbolUnit, SymbolBottom, SymbolUUID, SymbolType, SymbolTop, Type, Int, Bool, Double, Byte, Char, Unit, Bottom, Top, SymbolDynamic, Dynamic, SymbolOrdering, Ordering } from "./primitive_types.js";
|
||||||
|
|
||||||
export const ModulePrimitiveSymbols = [
|
export const ModulePrimitiveSymbols = [
|
||||||
newDynamic(SymbolInt )(UUID),
|
newDynamic(SymbolInt )(UUID),
|
||||||
|
|
@ -12,7 +12,8 @@ export const ModulePrimitiveSymbols = [
|
||||||
newDynamic(SymbolUUID )(UUID),
|
newDynamic(SymbolUUID )(UUID),
|
||||||
newDynamic(SymbolType )(UUID),
|
newDynamic(SymbolType )(UUID),
|
||||||
newDynamic(SymbolTop )(UUID),
|
newDynamic(SymbolTop )(UUID),
|
||||||
newDynamic(SymbolDynamic)(UUID),
|
newDynamic(SymbolDynamic )(UUID),
|
||||||
|
newDynamic(SymbolOrdering)(UUID),
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ModulePrimitiveTypes = [
|
export const ModulePrimitiveTypes = [
|
||||||
|
|
@ -26,5 +27,6 @@ export const ModulePrimitiveTypes = [
|
||||||
newDynamic(UUID )(Type),
|
newDynamic(UUID )(Type),
|
||||||
newDynamic(Type )(Type),
|
newDynamic(Type )(Type),
|
||||||
newDynamic(Top )(Type),
|
newDynamic(Top )(Type),
|
||||||
newDynamic(Dynamic)(Type),
|
newDynamic(Dynamic )(Type),
|
||||||
|
newDynamic(Ordering)(Type),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import { ModuleStructuralSymbols, ModuleTypeConstructors } from "./structures/ty
|
||||||
import { ModuleCompareTypes } from "./compare/type.types.js";
|
import { ModuleCompareTypes } from "./compare/type.types.js";
|
||||||
import { ModuleComparePrimitives } from "./compare/primitives.types.js";
|
import { ModuleComparePrimitives } from "./compare/primitives.types.js";
|
||||||
import { ModuleCompareStructures } from "./compare/structures.types.js";
|
import { ModuleCompareStructures } from "./compare/structures.types.js";
|
||||||
|
import { ModuleCompareDynamic } from "./compare/dynamic.types.js";
|
||||||
|
|
||||||
export const ModuleStd = [
|
export const ModuleStd = [
|
||||||
// Symbols (for nominal types)
|
// Symbols (for nominal types)
|
||||||
|
|
@ -45,4 +46,5 @@ export const ModuleStd = [
|
||||||
...ModuleCompareTypes,
|
...ModuleCompareTypes,
|
||||||
...ModuleComparePrimitives,
|
...ModuleComparePrimitives,
|
||||||
...ModuleCompareStructures,
|
...ModuleCompareStructures,
|
||||||
|
...ModuleCompareDynamic,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue