lotta progress

This commit is contained in:
Joeri Exelmans 2025-03-23 13:25:47 +01:00
parent 29d20b2273
commit bc91d9bf39
27 changed files with 317 additions and 475 deletions

View file

@ -1,16 +1,7 @@
import { makeGeneric } from "../generics/generics.js";
import { Type } from "../metacircular.js";
import { DefaultMap } from "../util.js";
import { typedFnType } from "./function.js";
const symbolProduct = Symbol("Product");
const productTypeRegistry = new DefaultMap(leftType => new DefaultMap(rightType => ({
symbol: symbolProduct,
params: [leftType, rightType],
})));
// type constructor
export const prodType = leftType => rightType => productTypeRegistry.getdefault(leftType, true).getdefault(rightType, true);
import { Type } from "../type.js";
import { typedFnType } from "./types.js";
import { prodType } from "./types.js";
// In JS, all products are encoded in the same way:
const constructor = left => right => ({left, right});
@ -20,32 +11,39 @@ const getRight = product => product.right;
export const ModuleProduct = {l: [
// binary type constructor
// Type -> Type -> Type
...typedFnType(prodType, fnType => fnType
(Type)
(fnType
...typedFnType(prodType, fnType =>
fnType
(Type)
(Type)
)
(fnType
(Type)
(Type)
)
),
// a -> b -> (a, b)
...typedFnType(constructor, fnType => makeGeneric((a, b) => fnType
(a)
(fnType
(b)
(prodType(a)(b))
)
)),
...typedFnType(constructor, fnType =>
makeGeneric((a, b) =>
fnType
(a)
(fnType
(b)
(prodType(a)(b))
)
)),
// (a, b) -> a
...typedFnType(getLeft, fnType => makeGeneric((a, b) => fnType
(prodType(a)(b))
(a)
)),
...typedFnType(getLeft, fnType =>
makeGeneric((a, b) =>
fnType
(prodType(a)(b))
(a)
)),
// (a, b) -> b
...typedFnType(getRight, fnType => makeGeneric((a, b) => fnType
(prodType(a)(b))
(b)
)),
...typedFnType(getRight, fnType =>
makeGeneric((a, b) =>
fnType
(prodType(a)(b))
(b)
)),
]};