can auto-generate comparison functions for composed types

This commit is contained in:
Joeri Exelmans 2025-04-17 16:43:28 +02:00
parent 0b262daf7f
commit 4d1fb81492
6 changed files with 72 additions and 35 deletions

View file

@ -1,4 +1,4 @@
import { Char, Double, Int } from "../primitives/types.js";
import { Char, Double, Int, Unit } from "../primitives/types.js";
export const compareNumbers = x => y => {
if (typeof(x) !== 'number' || typeof(y) !== 'number') {
@ -21,9 +21,5 @@ export const compareBools = x => y => {
return x - y;
};
export const typeToCmp = new Map([
[Int, compareNumbers],
[Char, compareStrings],
[Double, compareNumbers],
[Boolean, compareBools],
]);
// The Unit-type has only one instance, which is equal to itself:
export const compareUnits = x => y => 0;