simplify: no distinction between generic types and 'normal' types.

This commit is contained in:
Joeri Exelmans 2025-05-08 16:58:07 +02:00
parent b4826605af
commit a664ddac8a
27 changed files with 535 additions and 360 deletions

View file

@ -1,4 +1,4 @@
import { makeCompareFn } from "../lib/compare/registry.js";
import { makeCompareFn } from "../lib/compare/dynamic.js";
import { Int, Unit } from "../lib/primitives/primitive_types.js";
import { unit } from "../lib/primitives/unit.js";
import { makeConstructors, makeMatchFn } from "../lib/structures/enum.js";
@ -7,16 +7,18 @@ import { newProduct } from "../lib/structures/product.js";
import { lsType } from "../lib/structures/type_constructors.js";
import { prettyT } from "../lib/util/pretty.js";
Error.stackTraceLimit = Infinity;
const variants = [
newProduct("price")(Int),
newProduct("prices")(lsType(_ => Int)),
newProduct("not_found")(Unit),
newProduct("price")(_ => Int),
newProduct("prices")(_ => lsType(_ => Int)),
newProduct("not_found")(_ => Unit),
];
const myEnumType = enumType(variants);
const compatibleNestedSumType = enumType(variants);
console.log("observe the type that was generated:");
console.log(" ", prettyT(myEnumType));
console.log(" ", prettyT(compatibleNestedSumType));
const [newPrice, newPrices, newNotFound] = makeConstructors(variants);
@ -39,7 +41,7 @@ console.log(" ", myEnumToString(price));
console.log(" ", myEnumToString(prices));
console.log(" ", myEnumToString(notFound));
const compareMyEnum = makeCompareFn(myEnumType);
const compareMyEnum = makeCompareFn(compatibleNestedSumType);
console.log("observe the generated compare function in action:");
console.log(" should be smaller ->", compareMyEnum(price)(prices));