This commit is contained in:
Joeri Exelmans 2025-03-23 09:15:37 +01:00
parent afd78c3b3e
commit 29d20b2273
25 changed files with 369 additions and 469 deletions

View file

@ -1,39 +1,39 @@
import { fnType } from "../metacircular.js";
import {Function} from "../metacircular.js";
// import { fnType } from "../metacircular.js";
// import {Function} from "../metacircular.js";
// import {Typed} from "../typed.js";
// // import {Typed} from "../typed.js";
// import {Bool} from "../primitives/symbols.js";
// import {deepEqual} from "../util.js";
// import {Conformable, conformanceCheck} from "../typeclasses/conformable.js";
// // import {Bool} from "../primitives/symbols.js";
// // import {deepEqual} from "../util.js";
// // import {Conformable, conformanceCheck} from "../typeclasses/conformable.js";
// // Identity function
// const idBoundToType = Symbol('idBoundToType');
// // // Identity function
// // const idBoundToType = Symbol('idBoundToType');
// const id = type => x => x;
// const idFn = {name: "id", inType: Type, outType: {inType: Type, outType: Type}, fn: id};
// const idIsConform = {
// name: "isConform",
// inType: idBoundToType,
// outType: Bool,
// fn: fn => deepEqual(fnIn(fn), fnOut(fn))
// }
// // const id = type => x => x;
// // const idFn = {name: "id", inType: Type, outType: {inType: Type, outType: Type}, fn: id};
// // const idIsConform = {
// // name: "isConform",
// // inType: idBoundToType,
// // outType: Bool,
// // fn: fn => deepEqual(fnIn(fn), fnOut(fn))
// // }
// export const ModuleId = [
// {i: idBoundToType, t: Type},
// {i: idFn, t: Function},
// ... makeTypedFnInOut({f: idBoundToType, inType: Type, outType: Type}),
// // export const ModuleId = [
// // {i: idBoundToType, t: Type},
// // {i: idFn, t: Function},
// // ... makeTypedFnInOut({f: idBoundToType, inType: Type, outType: Type}),
// {i: idBoundToType, t: Conformable},
// {i: idIsConform, t: conformanceCheck},
// ];
// // {i: idBoundToType, t: Conformable},
// // {i: idIsConform, t: conformanceCheck},
// // ];
// generates explicitly typed id-function
export const makeIdFn = typ => {
const Typ_to_Typ = fnType({in: typ, out: typ});
const id = x => x;
return {l:[
{i: id , t: Typ_to_Typ},
{i: Typ_to_Typ, t: Function},
]};
};
// // generates explicitly typed id-function
// export const makeIdFn = typ => {
// const Typ_to_Typ = fnType({in: typ, out: typ});
// const id = x => x;
// return {l:[
// {i: id , t: Typ_to_Typ},
// {i: Typ_to_Typ, t: Function},
// ]};
// };

View file

@ -1,8 +1,8 @@
import {Function, getIn, getOut} from "../metacircular.js";
import {Module} from "../structures/list_types/module.js";
import { deepEqual } from "../util.js";
import { Typed } from "../typed.js";
import { fnType } from "../metacircular.js";
// import { getIn, getOut } from "../metacircular.js";
// import {Module} from "../structures/list_types/module.js";
// import { deepEqual } from "../util.js";
// import { Typed } from "../typed.js";
// import { fnType } from "../metacircular.js";
// import {Num, NumDict, getType, getMul} from "../typeclasses/num.js";
@ -27,24 +27,24 @@ import { fnType } from "../metacircular.js";
// ];
export const makeSquare = ({i: mul, t: mulFunction}) => {
const numType = getIn(mulFunction);
const boundMulFunction = getOut(mulFunction);
if (!deepEqual(getOut(boundMulFunction), numType) || !deepEqual(getIn(boundMulFunction), numType)) {
console.log(getOut(boundMulFunction), getIn(boundMulFunction), numType);
throw new Error("invalid signature");
}
const square = x => mul(x)(x);
const squareFunction = fnType({in: numType, out: numType});
return {l:[
{i: square , t: squareFunction},
{i: squareFunction, t: Function},
]};
};
// export const makeSquare = ({i: mul, t: mulFunction}) => {
// const numType = getIn(mulFunction);
// const boundMulFunction = getOut(mulFunction);
// if (!deepEqual(getOut(boundMulFunction), numType) || !deepEqual(getIn(boundMulFunction), numType)) {
// console.log(getOut(boundMulFunction), getIn(boundMulFunction), numType);
// throw new Error("invalid signature");
// }
// const square = x => mul(x)(x);
// const squareFunction = fnType({in: numType, out: numType});
// return {l:[
// {i: square , t: squareFunction},
// {i: squareFunction, t: Function},
// ]};
// };
const makeSquareType = fnType({in: Typed, out: Module});
// const makeSquareType = fnType({in: Typed, out: Module});
export const ModuleSquare = {l:[
{i: makeSquare , t: makeSquareType},
{i: makeSquareType, t: Function},
]};
// export const ModuleSquare = {l:[
// {i: makeSquare , t: makeSquareType},
// {i: makeSquareType, t: Function},
// ]};