add nominal types for 2D points
This commit is contained in:
parent
94efde3e65
commit
18b5e56ff0
6 changed files with 110 additions and 21 deletions
|
|
@ -2,6 +2,7 @@
|
|||
// Maybe we shouldn't use Symbols for types, but we also cannot use primitive values for types because they may accidentally overlap with 'real' values (that are not types)
|
||||
// We also cannot use objects for types because similar to Symbols, objects are only equal to themselves if we use them as Map keys.
|
||||
|
||||
import { Function } from "./metacircular.js";
|
||||
import { DefaultMap } from "./util.js";
|
||||
|
||||
// Global store of function types:
|
||||
|
|
@ -18,6 +19,19 @@ export const fnType = ({in: inType, out: outType}) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const typedFnType = (instance, callback) => {
|
||||
const fnTs = [];
|
||||
const wrappedFnType = ({in: inType, out: outType}) => {
|
||||
const fnT = fnType({in: inType, out: outType});
|
||||
fnTs.push(fnT);
|
||||
return fnT;
|
||||
}
|
||||
return [
|
||||
{i: instance, t: callback(wrappedFnType)},
|
||||
...fnTs.map(fnT => ({i: fnT, t: Function})),
|
||||
];
|
||||
}
|
||||
|
||||
// Global store of list types:
|
||||
const listTypes = new Map();
|
||||
export const lsType = (elementType) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue