dope2/lib/compare/versioning.js

35 lines
1 KiB
JavaScript

// 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;
}
if (slotB.depth < slotA.depth) {
return 1;
}
return compareValues(compareElems)(slotA.value)(slotB.value);
};
export const compareValues = compareElems => valA => valB => {
if (valA.kind < valB.kind) {
return -1;
}
if (valB.kind < valA.kind) {
return 1;
}
if (valA.kind === "literal") {
return compareElems(valA.out)(valB.out);
}
if (valA.kind === "read") {
return compareSlots(compareElems)(valA.slot)(valB.slot);
}
if (valA.kind === "transformation") {
const cmpIn = compareValues(compareElems)(valA.in)(valB.in);
if (cmpIn !== 0) {
return cmpIn;
}
return compareValues(compareElems)(valA.fn)(valB.fn);
}
};