simplify: no distinction between generic types and 'normal' types.
This commit is contained in:
parent
b4826605af
commit
a664ddac8a
27 changed files with 535 additions and 360 deletions
|
|
@ -1,22 +1,32 @@
|
|||
import { getInst, getType } from "../primitives/dynamic.js";
|
||||
import { SymbolBool, SymbolChar, SymbolDouble, SymbolInt, SymbolType, SymbolUnit } from "../primitives/primitive_types.js";
|
||||
import { symbolDict, symbolList, symbolProduct, symbolSet, symbolSum } from "../structures/type_constructors.js";
|
||||
import { compareBools, compareNumbers, compareStrings, compareUnits } from "./primitives.js";
|
||||
import { compareDicts, compareLists, compareProducts, compareSets, compareSums } from "./structures.js";
|
||||
import { SymbolBool, SymbolBottom, SymbolByte, SymbolChar, SymbolDouble, SymbolDynamic, SymbolInt, SymbolUUID, SymbolType, SymbolUnit } from "../primitives/primitive_types.js";
|
||||
import { symbolDict, symbolFunction, symbolList, symbolProduct, symbolSet, symbolSum } from "../structures/type_constructors.js";
|
||||
import { compareBools, compareNumbers, compareStrings, compareSymbols, compareUnits } from "./primitives.js";
|
||||
import { compareDicts, compareFunctions, compareLists, compareProducts, compareSets, compareSums } from "./structures.js";
|
||||
import { compareTypes } from "./type.js";
|
||||
|
||||
export const compareDynamic = x => y =>
|
||||
compareTypes(getType(x))(getType(y))
|
||||
|| makeCompareFn(getType(x))(getInst(x))(getInst(y));
|
||||
|
||||
const typeSymbolToCmp = new Map([
|
||||
[SymbolInt , compareNumbers],
|
||||
[SymbolChar , compareStrings],
|
||||
[SymbolDouble , compareNumbers],
|
||||
[SymbolBool , compareBools],
|
||||
[SymbolDouble , compareNumbers],
|
||||
[SymbolByte , compareNumbers],
|
||||
[SymbolChar , compareStrings],
|
||||
[SymbolUnit , compareUnits],
|
||||
[SymbolBottom , _ => _ => { throw new Error("Bottom!"); }],
|
||||
[SymbolUUID , compareSymbols],
|
||||
// [SymbolGenericType, ?] TODO
|
||||
[SymbolType , compareTypes],
|
||||
[SymbolDynamic, compareDynamic],
|
||||
|
||||
// these functions take extra comparison callbacks:
|
||||
[symbolList , compareLists],
|
||||
[symbolProduct , compareProducts],
|
||||
[symbolFunction, compareFunctions],
|
||||
[symbolSum , compareSums],
|
||||
[symbolProduct , compareProducts],
|
||||
[symbolList , compareLists],
|
||||
[symbolSet , compareSets],
|
||||
[symbolDict , compareDicts],
|
||||
]);
|
||||
|
|
@ -27,7 +37,3 @@ export const makeCompareFn = type => {
|
|||
typeSymbolToCmp.get(type.symbol)
|
||||
);
|
||||
};
|
||||
|
||||
export const compareDynamic = x => y =>
|
||||
compareTypes(getType(x))(getType(y))
|
||||
|| makeCompareFn(getType(x))(getInst(x))(getInst(y));
|
||||
9
lib/compare/dynamic.types.js
Normal file
9
lib/compare/dynamic.types.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
||||
import { compareDynamic, makeCompareFn } from "./dynamic.js";
|
||||
|
||||
const mkType = getDefaultTypeParser();
|
||||
|
||||
export const ModuleCompareDynamic = [
|
||||
{i: makeCompareFn , t: mkType("∀a: Type -> a -> a -> Int")},
|
||||
{i: compareDynamic, t: mkType("Dynamic -> Dynamic -> Int")},
|
||||
];
|
||||
|
|
@ -1,12 +1,17 @@
|
|||
// Total ordering of composed types
|
||||
|
||||
import { compareNumbers } from "./primitives.js"
|
||||
import { compareNumbers, compareStrings } from "./primitives.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 readDict, length as lengthDict, first as firstDict } from "../structures/dict.js";
|
||||
import { getLeft, getRight } from "../structures/product.js";
|
||||
import { match } from "../structures/sum.js";
|
||||
|
||||
export const compareFunctions = _compareInput => _compareOutput => x => y => {
|
||||
// dirty but does the job
|
||||
return compareStrings(x.toString())(y.toString());
|
||||
}
|
||||
|
||||
export const compareLists = compareElems => x => y => {
|
||||
return compareNumbers(lengthLs(x))(lengthLs(y))
|
||||
|| (() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue