can auto-generate comparison functions for composed types
This commit is contained in:
parent
0b262daf7f
commit
4d1fb81492
6 changed files with 72 additions and 35 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue