move function
This commit is contained in:
parent
c1ac3c0d60
commit
e04cac4f7d
3 changed files with 10 additions and 9 deletions
|
|
@ -1,7 +1,5 @@
|
||||||
// Total ordering of primitive types
|
// Total ordering of primitive types
|
||||||
|
|
||||||
import { getSymbol } from "../type_constructor.js";
|
|
||||||
|
|
||||||
export const compareNumbers = x => y => {
|
export const compareNumbers = 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}`);
|
||||||
|
|
@ -26,12 +24,6 @@ export const compareBools = x => y => {
|
||||||
// The Unit-type has only one instance, which is equal to itself:
|
// The Unit-type has only one instance, which is equal to itself:
|
||||||
export const compareUnits = x => y => 0;
|
export const compareUnits = x => y => 0;
|
||||||
|
|
||||||
export const compareTypes = x => y => {
|
|
||||||
return compareSymbols(getSymbol(x))(getSymbol(y))
|
|
||||||
|| compareNumbers(x.params.length)(y.params.length)
|
|
||||||
|| x.params.reduce((acc, _, i) => acc || compareTypes(x.params[i])(y.params[i]), 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: dirty assumption that every symbol has unique description.
|
// Note: dirty assumption that every symbol has unique description.
|
||||||
// This will be fixed once we move from symbols to real UUIDs.
|
// This will be fixed once we move from symbols to real UUIDs.
|
||||||
export const compareSymbols = a => b => (a !== b) && compareStrings(a.description)(b.description);
|
export const compareSymbols = a => b => (a !== b) && compareStrings(a.description)(b.description);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import { SymbolBool, SymbolChar, SymbolDouble, SymbolInt, SymbolUnit } from "../primitives/types.js";
|
import { SymbolBool, SymbolChar, SymbolDouble, SymbolInt, SymbolType, SymbolUnit } from "../primitives/types.js";
|
||||||
import { symbolList, symbolProduct, symbolSet, symbolSum } from "../structures/types.js";
|
import { symbolList, symbolProduct, symbolSet, symbolSum } from "../structures/types.js";
|
||||||
import { compareBools, compareNumbers, compareStrings, compareUnits } from "./primitives.js";
|
import { compareBools, compareNumbers, compareStrings, compareUnits } from "./primitives.js";
|
||||||
import { compareLists, compareProducts, compareSets, compareSums } from "./structures.js";
|
import { compareLists, compareProducts, compareSets, compareSums } from "./structures.js";
|
||||||
|
import { compareTypes } from "./type.js";
|
||||||
|
|
||||||
const typeSymbolToCmp = new Map([
|
const typeSymbolToCmp = new Map([
|
||||||
[SymbolInt , compareNumbers],
|
[SymbolInt , compareNumbers],
|
||||||
|
|
@ -9,6 +10,7 @@ const typeSymbolToCmp = new Map([
|
||||||
[SymbolDouble, compareNumbers],
|
[SymbolDouble, compareNumbers],
|
||||||
[SymbolBool , compareBools],
|
[SymbolBool , compareBools],
|
||||||
[SymbolUnit , compareUnits],
|
[SymbolUnit , compareUnits],
|
||||||
|
[SymbolType , compareTypes],
|
||||||
|
|
||||||
// these functions take extra comparison callbacks:
|
// these functions take extra comparison callbacks:
|
||||||
[symbolList , compareLists],
|
[symbolList , compareLists],
|
||||||
|
|
|
||||||
7
compare/type.js
Normal file
7
compare/type.js
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { getParams, getSymbol } from "../type_constructor.js";
|
||||||
|
import { compareSymbols } from "./primitives.js";
|
||||||
|
import { compareLists } from "./structures.js";
|
||||||
|
|
||||||
|
export const compareTypes = x => y =>
|
||||||
|
compareSymbols(getSymbol(x))(getSymbol(y))
|
||||||
|
|| compareLists(compareTypes)(getParams(x))(getParams(y));
|
||||||
Loading…
Add table
Add a link
Reference in a new issue