fix bug in type inferencing
This commit is contained in:
parent
bb6e742f5f
commit
c3f7cea310
8 changed files with 205 additions and 155 deletions
|
|
@ -4,7 +4,7 @@ import { eqType, getSymbol, reduceUnification } from "dope2";
|
|||
|
||||
import { ExprBlock, type ExprBlockState, type State2Props } from "./ExprBlock";
|
||||
import { EnvContext } from "./EnvContext";
|
||||
import { evalExprBlock, makeInnerEnv, makeTypeVar } from "./eval";
|
||||
import { evalExprBlock, evalLambdaBlock, makeInnerEnv, makeTypeVar } from "./eval";
|
||||
|
||||
import "./LambdaBlock.css";
|
||||
import { Type } from "./Type";
|
||||
|
|
@ -36,20 +36,10 @@ export function LambdaBlock({state, setState, score}: LambdaBlockProps) {
|
|||
expr: callback(state.expr),
|
||||
}));
|
||||
|
||||
const [paramType, staticInnerEnv] = makeTypeVar(env, state.paramName);
|
||||
const [lambdaResolved, _, innerEnv] = evalLambdaBlock(state.paramName, state.expr, env);
|
||||
|
||||
const [exprResolved] = evalExprBlock(state.expr, staticInnerEnv);
|
||||
const inferredParamType = lambdaResolved.t.params[0](lambdaResolved.t);
|
||||
|
||||
const inferredParamType = reduceUnification(exprResolved.unification).get(getSymbol(paramType)) || paramType;
|
||||
|
||||
const betterInnerEnv = eqType(paramType)(inferredParamType)
|
||||
? staticInnerEnv
|
||||
: makeInnerEnv(env, state.paramName, {
|
||||
kind: "unknown",
|
||||
t: inferredParamType,
|
||||
unification: new Map(), // <- is this correct?
|
||||
});
|
||||
|
||||
return <span className="lambdaBlock">
|
||||
<span className="keyword">λ</span>
|
||||
|
||||
|
|
@ -71,7 +61,7 @@ export function LambdaBlock({state, setState, score}: LambdaBlockProps) {
|
|||
<span className="keyword">:</span>
|
||||
|
||||
<div className="lambdaInner">
|
||||
<EnvContext value={betterInnerEnv}>
|
||||
<EnvContext value={innerEnv}>
|
||||
<ExprBlock
|
||||
state={state.expr}
|
||||
setState={setExpr}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue