refactor a bit more

This commit is contained in:
Joeri Exelmans 2025-05-20 15:35:39 +02:00
parent 230916ceb1
commit fdbf43a4e9
11 changed files with 79 additions and 90 deletions

View file

@ -1,4 +1,4 @@
import { Double, fnType, getHumanReadableName, getSymbol, Int, mergeUnifications, NotAFunctionError, occurring, prettyT, prettyU, recomputeTypeVars, reduceUnification, substitute, symbolFunction, trie, TYPE_VARS, UNBOUND_SYMBOLS, UnifyError, unifyLL, transitivelyGrow, isTypeVar, set, compareTypes, recomputeTypeVarsWithInverse } from "dope2";
import { Double, fnType, getHumanReadableName, getSymbol, Int, isTypeVar, mergeUnifications, NotAFunctionError, occurring, prettyT, prettyU, recomputeTypeVarsWithInverse, reduceUnification, substitute, symbolFunction, trie, TYPE_VARS, UNBOUND_SYMBOLS, UnifyError, unifyLL } from "dope2";
import type { ExprBlockState } from "./ExprBlock";
import type { InputValueType } from "./InputBlock";
@ -90,13 +90,15 @@ export function evalInputBlock(text: string, value: InputValueType, env: Environ
export function evalCallBlock(fn: ExprBlockState, input: ExprBlockState, env: Environment): [ResolvedType,Environment] {
const [fnResolved, env2] = evalEditorBlock(fn, env);
const [inputResolved, env3] = evalEditorBlock(input, env2);
console.log('==== evalCallBlock ====');
console.log('env :', env);
console.log('fnResolved :', fnResolved);
console.log('env2 :', env2);
console.log('inputResolved:', inputResolved);
console.log('env3 :', env3);
console.log('=======================');
if (VERBOSE) {
console.log('==== evalCallBlock ====');
console.log('env :', env);
console.log('fnResolved :', fnResolved);
console.log('env2 :', env2);
console.log('inputResolved:', inputResolved);
console.log('env3 :', env3);
console.log('=======================');
}
return evalCallBlock2(fnResolved, inputResolved, env3);
}
@ -236,7 +238,7 @@ function evalCallBlock3(fnResolved: ResolvedType, inputResolved: ResolvedType, e
// if the above statement did not throw => types are compatible...
if (inputResolved.kind === "value" && fnResolved.kind === "value") {
const outValue = fnResolved.i(inputResolved.i);
console.log('outValue:', outValue);
// console.log('outValue:', outValue);
return [{
kind: "value",
i: outValue,
@ -255,7 +257,9 @@ function evalCallBlock3(fnResolved: ResolvedType, inputResolved: ResolvedType, e
}
catch (e) {
// if ((e instanceof UnifyError)) {
console.log('UnifyError!', (e as Error).message);
if (VERBOSE) {
console.log('UnifyError!', (e as Error).message);
}
// even though fn was incompatible with the given parameter, we can still suppose that our output-type will be that of fn...?
const outType = fnResolved.t.params[1](fnResolved.t);
try {