basic functionality, no generics
This commit is contained in:
commit
a8260f2afb
17 changed files with 615 additions and 0 deletions
33
typeclasses/conformable.js
Normal file
33
typeclasses/conformable.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// import {Type, Function, makeTypedFnInOut, fnOut} from "../metacircular.js";
|
||||
// import {Bool} from "../primitives/symbols.js";
|
||||
|
||||
// export const Conformable = Symbol('Conformable');
|
||||
// export const conformanceCheck = Symbol('conformanceCheck');
|
||||
|
||||
// export const ModuleConformable = [
|
||||
// {i: Conformable , t: Type},
|
||||
// {i: conformanceCheck, t: Function},
|
||||
|
||||
// // Note: outType is just 'Type', we cannot use Bool because a function that has type 'conformanceCheck' will have outType Bool, therefore conformanceCheck must return the type of Bool, which is Type.
|
||||
// ...makeTypedFnInOut({f: conformanceCheck, inType: Conformable, outType: Type}),
|
||||
// ];
|
||||
|
||||
|
||||
|
||||
// ////////////////////////////////////////////////////////
|
||||
// // Conformance check functions are themselves conformance checkable
|
||||
// // This is because we want to restrict their return type to Bool
|
||||
|
||||
// const conformanceCheckIsConform = fn => {
|
||||
// return fnOut(fn) === Bool;
|
||||
// };
|
||||
|
||||
// const conformanceCheckIsConformFn = {name: "isConform", inType: conformanceCheck, outType: Bool, fn: conformanceCheckIsConform};
|
||||
|
||||
|
||||
// export const ModuleConformanceCheckConforms = [
|
||||
// // instances of conformanceCheck (= 'isConform'-functions) are themselves conformance checkable
|
||||
// {i: conformanceCheck, t: Conformable},
|
||||
// {i: conformanceCheckIsConformFn, t: conformanceCheck},
|
||||
// {i: conformanceCheckIsConformFn, t: Function},
|
||||
// ];
|
||||
52
typeclasses/num.js
Normal file
52
typeclasses/num.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// import {Type, Function, makeTypedFnInOut, fnIn, fnOut} from "../metacircular.js";
|
||||
// import {Conformable, conformanceCheck} from "./conformable.js";
|
||||
// import {Bool} from "../primitives/symbols.js";
|
||||
// import {deepEqual} from "../util.js";
|
||||
|
||||
// export const Num = Symbol('Num');
|
||||
// export const NumDict = Symbol('NumDict');
|
||||
// // export const addType = Symbol('addType');
|
||||
// // export const addBoundType = Symbol('addBoundType');
|
||||
// // export const mulType = Symbol('mulType');
|
||||
// // export const mulBoundType = Symbol('mulBoundType');
|
||||
|
||||
// // export const getType = numDict => numDict.type;
|
||||
|
||||
// export const getAdd = numDict => numDict.add;
|
||||
// export const getMul = numDict => numDict.mul;
|
||||
|
||||
// // const addOrMulIsConform = fn => {
|
||||
// // // function signature must be: a -> a -> a
|
||||
// // const i0 = fnIn(fn);
|
||||
// // const o0 = fnOut(fn);
|
||||
// // const i1 = fnIn(o0);
|
||||
// // const o1 = fnOut(o0);
|
||||
// // return deepEqual(i0, i1) && deepEqual(i1, o1);
|
||||
// // };
|
||||
|
||||
// // const addIsConform = {name: "isConform", inType: addType, outType: Bool, fn: addOrMulIsConform};
|
||||
// // const mulIsConform = {name: "isConform", inType: mulType, outType: Bool, fn: addOrMulIsConform};
|
||||
|
||||
// export const ModuleNum = [
|
||||
// {i: Num, t: Type},
|
||||
// {i: NumDict, t: Type},
|
||||
// {i: addType, t: Type},
|
||||
// {i: addBoundType, t: Type},
|
||||
// {i: mulType, t: Type},
|
||||
// {i: mulBoundType, t: Type},
|
||||
// {i: {name: "getType", inType: NumDict, outType: Num, fn: getType}, t: Function},
|
||||
// {i: {name: "getAdd", inType: NumDict, outType: addType, fn: getAdd }, t: Function},
|
||||
// {i: {name: "getMul", inType: NumDict, outType: mulType, fn: getMul }, t: Function},
|
||||
// ...makeTypedFnInOut({f: addType , inType: Num, outType: addBoundType}),
|
||||
// ...makeTypedFnInOut({f: addBoundType, inType: Num, outType: Num }),
|
||||
// ...makeTypedFnInOut({f: mulType , inType: Num, outType: mulBoundType}),
|
||||
// ...makeTypedFnInOut({f: mulBoundType, inType: Num, outType: Num }),
|
||||
|
||||
// // conformance checking type class
|
||||
// {i: addType, t: Conformable},
|
||||
// {i: mulType, t: Conformable},
|
||||
// {i: addIsConform, t: Function},
|
||||
// {i: addIsConform, t: conformanceCheck},
|
||||
// {i: mulIsConform, t: Function},
|
||||
// {i: mulIsConform, t: conformanceCheck},
|
||||
// ];
|
||||
Loading…
Add table
Add a link
Reference in a new issue