improve type inferencing + fix bug in CallBlock suggestion priorities
This commit is contained in:
parent
24689b3783
commit
c45f19143b
6 changed files with 156 additions and 765 deletions
22
src/eval.ts
22
src/eval.ts
|
|
@ -97,11 +97,11 @@ export function evalCallBlock2(fnResolved: ResolvedType, inputResolved: Resolved
|
|||
}
|
||||
try {
|
||||
// fn is a function...
|
||||
const [outType, substitutions] = assignFnSubstitutions(fnResolved.t, inputResolved.t); // may throw
|
||||
const [_inType, inSubst, outType, _outSubst] = assignFnSubstitutions(fnResolved.t, inputResolved.t, getUnusedTypeVarIdx(env)); // may throw
|
||||
|
||||
// console.log('assignFn...', prettyT(fnResolved.t), inputResolved.i, prettyT(inputResolved.t), '\nout =', prettyT(outType), substitutions);
|
||||
// console.log('assignFn...', 'fn.t:', prettyT(fnResolved.t), 'input:', inputResolved, 'input.t:', prettyT(inputResolved.t), '\nout =', prettyT(outType), 'subst:', substitutions, substitutions.size);
|
||||
|
||||
const mergedSubstitutions = mergeMaps(substitutions, fnResolved.substitutions, inputResolved.substitutions);
|
||||
const mergedSubstitutions = mergeMaps(inSubst, fnResolved.substitutions, inputResolved.substitutions);
|
||||
|
||||
if (inputResolved.kind === "error") {
|
||||
return {
|
||||
|
|
@ -171,14 +171,18 @@ export function evalLetInBlock(value: EditorState, name: string, inner: EditorSt
|
|||
return evalEditorBlock(inner, innerEnv);
|
||||
}
|
||||
|
||||
export function getUnusedTypeVar(env) {
|
||||
function getUnusedTypeVarIdx(env) {
|
||||
for (let i=0; ; i++) {
|
||||
if (!dict.has(env.typeDict)(TYPE_VARS[i])) {
|
||||
return TYPE_VARS[i];
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getUnusedTypeVar(env) {
|
||||
return TYPE_VARS[getUnusedTypeVarIdx(env)];
|
||||
}
|
||||
|
||||
export function evalLambdaBlock(paramName: string, expr: EditorState, env): ResolvedType {
|
||||
const paramType = getUnusedTypeVar(env);
|
||||
// static env: we only know the name and the type
|
||||
|
|
@ -187,11 +191,6 @@ export function evalLambdaBlock(paramName: string, expr: EditorState, env): Reso
|
|||
t: paramType,
|
||||
substitutions: new Map(),
|
||||
})
|
||||
// const staticInnerEnv = makeInnerEnv(env, paramName, {
|
||||
// kind: "unknown", // parameter value is not statically known
|
||||
// t: paramType,
|
||||
// substitutions: new Map(),
|
||||
// });
|
||||
const exprResolved = evalEditorBlock(expr, staticInnerEnv);
|
||||
const lambdaT = fnType(_ => paramType)(_ => exprResolved.t);
|
||||
const lambdaTSubstituted = substitute(lambdaT, exprResolved.substitutions, []);
|
||||
|
|
@ -202,7 +201,8 @@ export function evalLambdaBlock(paramName: string, expr: EditorState, env): Reso
|
|||
t: lambdaTSubstituted,
|
||||
depth: 0,
|
||||
e: exprResolved.e,
|
||||
substitutions: staticInnerEnv.substitutions,
|
||||
// substitutions: new Map(),
|
||||
substitutions: exprResolved.substitutions,
|
||||
}
|
||||
}
|
||||
const paramTypeSubstituted = lambdaTSubstituted.params[0](lambdaTSubstituted);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue