rename some things

This commit is contained in:
Joeri Exelmans 2025-04-20 21:09:51 +02:00
parent e04cac4f7d
commit 8a4bd44f04
16 changed files with 92 additions and 60 deletions

View file

@ -1,7 +1,7 @@
import { Bottom } from "../primitives/types.js";
import { capitalizeFirstLetter } from "../util/util.js";
import { constructorProduct, getLeft, getRight } from "./product.js";
import { constructorLeft, constructorRight, match } from "./sum.js";
import { newProduct as newProduct, getLeft, getRight } from "./product.js";
import { newLeft, newRight, match } from "./sum.js";
import { sumType } from "./types.js";
// 'variants' is an array of (name: string, type: Type) pairs.
@ -34,7 +34,7 @@ export const makeMatchFn = variants => {
const [_, ...remainingVariants] = variants;
return sum => handler => {
return (
match(sum)(constructorProduct
match(sum)(newProduct
(leftValue => eatParameters(remainingVariants.length, handler(leftValue)))
(rightValue => makeMatchFn(remainingVariants)(rightValue))
));
@ -48,10 +48,10 @@ export const makeConstructors = variants => {
const [variant, ...remainingVariants] = variants;
const name = getLeft(variant);
const ctorName = `new${capitalizeFirstLetter(name)}`;
const constructor = { [ctorName]: val => constructorLeft(val) }[ctorName];
const constructor = { [ctorName]: val => newLeft(val) }[ctorName];
return [
constructor,
...makeConstructors(remainingVariants).map(ctor =>
({[ctor.name]: val => constructorRight(ctor(val))}[ctor.name])),
({[ctor.name]: val => newRight(ctor(val))}[ctor.name])),
];
}