use unused typevar when encountering unknown value or lambda parameter - type inferencing still not entirely correct
This commit is contained in:
parent
d7a4e210a2
commit
496463bbac
8 changed files with 94 additions and 66 deletions
|
|
@ -7,6 +7,7 @@ import { growEnv, TYPE_VARS } from "dope2";
|
|||
import { autoInputWidth } from "./util/dom_trickery";
|
||||
|
||||
import "./LambdaBlock.css";
|
||||
import { getUnusedTypeVar } from "./eval";
|
||||
|
||||
|
||||
export interface LambdaBlockState {
|
||||
|
|
@ -31,12 +32,18 @@ export function LambdaBlock({state, setState, suggestionPriority}: LambdaBlockPr
|
|||
...state,
|
||||
paramName,
|
||||
}));
|
||||
|
||||
const setExpr = callback => setState(state => ({
|
||||
...state,
|
||||
expr: callback(state.expr),
|
||||
}));
|
||||
|
||||
const onChangeName = (e) => {
|
||||
if (state.paramName === "" && e.key === 'Backspace') {
|
||||
setState(state => state.expr);
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
nameRef.current?.focus();
|
||||
}, []);
|
||||
|
|
@ -46,7 +53,7 @@ export function LambdaBlock({state, setState, suggestionPriority}: LambdaBlockPr
|
|||
const innerEnv = growEnv(env)(state.paramName)({
|
||||
kind: "unknown",
|
||||
i: undefined,
|
||||
t: TYPE_VARS[0],
|
||||
t: getUnusedTypeVar(env),
|
||||
});
|
||||
|
||||
return <span>
|
||||
|
|
@ -58,13 +65,14 @@ export function LambdaBlock({state, setState, suggestionPriority}: LambdaBlockPr
|
|||
className='editable'
|
||||
value={state.paramName}
|
||||
placeholder="<name>"
|
||||
onKeyDown={onChangeName}
|
||||
onChange={e => setParamName(e.target.value)}
|
||||
/>
|
||||
</span>
|
||||
|
||||
<span className="keyword">:</span>
|
||||
|
||||
<span className="lambdaExpr">
|
||||
<div className="lambdaExpr">
|
||||
<EnvContext value={innerEnv}>
|
||||
<Editor
|
||||
state={state.expr}
|
||||
|
|
@ -75,6 +83,6 @@ export function LambdaBlock({state, setState, suggestionPriority}: LambdaBlockPr
|
|||
}}
|
||||
/>
|
||||
</EnvContext>
|
||||
</span>
|
||||
</div>
|
||||
</span>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue