infer all types once at the root level, and pass the result down deeply

This commit is contained in:
Joeri Exelmans 2025-05-25 08:58:21 +02:00
parent b2584a2495
commit d000839878
6 changed files with 75 additions and 80 deletions

View file

@ -1,15 +1,12 @@
import { useContext } from "react";
// import { eqType, getSymbol, reduceUnification } from "dope2";
import { ExprBlock, type ExprBlockState, type State2Props } from "./ExprBlock";
import { EnvContext } from "../../context/EnvContext";
// import { evalExprBlock, evalLambdaBlock, makeInnerEnv, makeTypeVar } from "./eval";
import { ExprBlock, type ExprBlockState, type State2Props } from "./ExprBlock";
import "./LambdaBlock.css";
import { Type } from "../other/Type";
import { type TypeInfoLambda } from "../../eval/infer_type";
import { Input } from "../other/Input";
import { inferTypeLambda } from "../../eval/infer_type";
import { Type } from "../other/Type";
import "./LambdaBlock.css";
export interface LambdaBlockState {
kind: "lambda";
@ -22,10 +19,11 @@ export interface LambdaBlockProps<
FnState=ExprBlockState,
InputState=ExprBlockState,
> extends State2Props<LambdaBlockState,ExprBlockState> {
typeInfo: TypeInfoLambda;
}
export function LambdaBlock({state, setState, score}: LambdaBlockProps) {
export function LambdaBlock({state, setState, score, typeInfo}: LambdaBlockProps) {
const env = useContext(EnvContext);
const setParamName = paramName => setState(state => ({
@ -37,14 +35,6 @@ export function LambdaBlock({state, setState, score}: LambdaBlockProps) {
expr: callback(state.expr),
}));
const {paramType, innerEnv} = inferTypeLambda(state, env);
// const [lambdaResolved, _, innerEnv] = evalLambdaBlock(state.paramName, state.expr, env);
// const inferredParamType = lambdaResolved.t.params[0](lambdaResolved.t);
// const innerEnv = env; // todo: change this
return <span className="lambdaBlock">
<span className="keyword">&#955;</span>
&nbsp;
@ -60,18 +50,19 @@ export function LambdaBlock({state, setState, score}: LambdaBlockProps) {
/>
</span>
<div className="typeSignature">
&nbsp;::&nbsp;<Type type={paramType} />
&nbsp;::&nbsp;<Type type={typeInfo.paramType} />
</div>
&nbsp;
<span className="keyword">:</span>
&nbsp;
<div className="lambdaInner">
<EnvContext value={innerEnv}>
<EnvContext value={typeInfo.innerEnv}>
<ExprBlock
state={state.expr}
setState={setExpr}
onCancel={() => setState(state => state.expr)}
score={suggestion => score({...state, expr: suggestion})}
typeInfo={typeInfo.inner}
/>
</EnvContext>
</div>