Compare commits

...

3 commits

Author SHA1 Message Date
3be17c1148 doc 2025-04-18 09:14:55 +02:00
c51e517b66 fix missing return stmt 2025-04-18 09:14:42 +02:00
28f60e77be rename dir scripts -> examples 2025-04-18 09:14:09 +02:00
10 changed files with 15 additions and 11 deletions

View file

@ -1,4 +1,4 @@
import { Char, Double, Int, Unit } from "../primitives/types.js";
// Total ordering of primitive types
export const compareNumbers = x => y => {
if (typeof(x) !== 'number' || typeof(y) !== 'number') {

View file

@ -1,10 +1,10 @@
// Total ordering of composed types
import { compareNumbers } from "./primitives.js"
import { get, length as lengthLs } from "../structures/list.js";
import { read, length as lengthSet } from "../structures/set.js";
import { constructorProduct, getLeft, getRight } from "../structures/product.js";
import { match } from "../structures/sum.js";
import { makeGeneric } from "../generics/generics.js";
import { lsType } from "../structures/types.js";
// (a -> a -> Int) -> [a] -> [a] -> Int
export const compareLists = compareElems => x => y => {
@ -48,13 +48,13 @@ export const compareSets = compareElems => x => y => {
// because of the underlying red-black tree, iteration happens in ordered fashion
const iterate = iterX => iterY =>
read(iterX)
(keyX => nextX =>
read(iterY)
// we could also use the comparison function that is embedded in the set object,
// but to be consistent with the other comparison-functions, we don't.
(keyY => nextY => compareElems(keyX)(keyY) || iterate(nextX)(nextY))
(0)) // end of set y (we'll never get here because sets are same size)
(0) // end of set x;
iterate(first(x))(first(y));
(keyX => nextX =>
read(iterY)
// we could also use the comparison function that is embedded in the set object,
// but to be consistent with the other comparison-functions, we don't.
(keyY => nextY => compareElems(keyX)(keyY) || iterate(nextX)(nextY))
(0)) // end of set y (we'll never get here because sets are same size)
(0); // end of set x
return iterate(first(x))(first(y));
})();
};

View file

@ -1,3 +1,7 @@
// Total ordering of slots and values (versioning library).
// Problem: A Value produced by a transformation can depend on other Values of any type!
// So, we cannot statically know the entire type -> resort to dynamic typing for these?
export const compareSlots = compareElems => slotA => slotB => {
if (slotA.depth < slotB.depth) {
return -1;