add extra check and error type
This commit is contained in:
parent
e631f11aa5
commit
1e10393e76
2 changed files with 7 additions and 1 deletions
2
index.d.ts
vendored
2
index.d.ts
vendored
|
|
@ -167,6 +167,8 @@ export function RBTreeWrapper(...args: any[]): any;
|
|||
|
||||
export function UnifyError(...args: any[]): any;
|
||||
|
||||
export function NotAFunctionError(...args: any[]): any;
|
||||
|
||||
export function addDouble(x: any): any;
|
||||
|
||||
export function addInt(x: any): any;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { zip } from "../util/util.js";
|
|||
import { pretty, prettyT } from '../util/pretty.js';
|
||||
import { isTypeVar, TYPE_VARS } from "../primitives/typevars.js";
|
||||
import { inspectType } from "../meta/type_constructor.js";
|
||||
import { symbolFunction } from "../structures/type_constructors.js";
|
||||
|
||||
// helper for creating generic types
|
||||
// for instance, the type:
|
||||
|
|
@ -78,6 +79,7 @@ export const mergeTwoWay = (m1, m2) => {
|
|||
};
|
||||
|
||||
export class UnifyError extends Error {}
|
||||
export class NotAFunctionError extends Error {}
|
||||
|
||||
// Thanks to Hans for pointing out that this algorithm exactly like "Unification" in Prolog (hence the function name):
|
||||
// https://www.dai.ed.ac.uk/groups/ssp/bookpages/quickprolog/node12.html
|
||||
|
|
@ -184,8 +186,10 @@ export const substitute = (type, substitutions, stack=[]) => {
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
export const assignFn = (funType, paramType) => {
|
||||
if (getSymbol(funType) !== symbolFunction) {
|
||||
throw NotAFunctionError(`${prettyT(funType)} is not a function type!`);
|
||||
}
|
||||
[funType, paramType] = recomputeTypeVars([funType, paramType]);
|
||||
// console.log(prettyT(funType), prettyT(paramType));
|
||||
const [inType, outType] = funType.params.map(p => p(funType));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue