diff --git a/src/App.tsx b/src/App.tsx index 613bd70..19ddda8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -166,7 +166,10 @@ export function App() { state={appState.history.at(-1)!} setState={pushHistory} onCancel={() => {}} - suggestionPriority={() => 1} + suggestionPriority={() => { + // console.log('suggestionPriority of App, always 0'); + return 0; + }} /> diff --git a/src/CallBlock.tsx b/src/CallBlock.tsx index 881e14d..74fe302 100644 --- a/src/CallBlock.tsx +++ b/src/CallBlock.tsx @@ -2,7 +2,7 @@ import { useContext } from "react"; import "./CallBlock.css"; import { Editor, type EditorState, type SetStateFn, type State2Props } from "./Editor"; -import { EnvContext } from "./EnvContext"; +import { EnvContext, functionWith3Params, functionWith4Params } from "./EnvContext"; import { evalCallBlock2, evalEditorBlock, scoreResolved, type ResolvedType } from "./eval"; import { Value } from "./Value"; import { GlobalContext } from "./GlobalContext"; diff --git a/src/Editor.css b/src/Editor.css index 4b0b07a..ea500a3 100644 --- a/src/Editor.css +++ b/src/Editor.css @@ -5,6 +5,10 @@ border: 1px solid red; display: inline-block; } +.editor.unknown { + border: 1px dashed dodgerblue; + display: inline-block; +} .offending .error { background-color: transparent; diff --git a/src/Editor.tsx b/src/Editor.tsx index 28f9baf..b933d3d 100644 --- a/src/Editor.tsx +++ b/src/Editor.tsx @@ -183,7 +183,7 @@ export function Editor({state, setState, onCancel, suggestionPriority}: EditorPr } } const resolved = evalEditorBlock(state, env); - return + return {renderBlock()}
 ::  diff --git a/src/EnvContext.ts b/src/EnvContext.ts index a64f478..f2d100e 100644 --- a/src/EnvContext.ts +++ b/src/EnvContext.ts @@ -1,10 +1,13 @@ import { createContext } from "react"; import { getDefaultTypeParser, module2Env, ModuleStd } from "dope2"; +export const functionWith3Params = i => j => k => i+j+k; +export const functionWith4Params = i => j => k => l => i+j+k+l; + const mkType = getDefaultTypeParser(); export const extendedEnv = module2Env(ModuleStd.concat([ - ["functionWith3Params", { i: i => j => k => i + j + k, t: mkType("Int->Int->Int->Int") }], - ["functionWith4Params", { i: i => j => k => l => i+j+k+l, t: mkType("Int->Int->Int->Int->Int")}] + ["functionWith3Params", { i: functionWith3Params, t: mkType("Int->Int->Int->Int") }], + ["functionWith4Params", { i: functionWith4Params, t: mkType("Int->Int->Int->Int->Int")}] ])); export const EnvContext = createContext(extendedEnv); \ No newline at end of file diff --git a/src/LambdaBlock.tsx b/src/LambdaBlock.tsx index 7ec7aa5..f3c4603 100644 --- a/src/LambdaBlock.tsx +++ b/src/LambdaBlock.tsx @@ -4,7 +4,7 @@ import { growEnv } from "dope2"; import { Editor, type EditorState, type State2Props } from "./Editor"; import { EnvContext } from "./EnvContext"; -import { getUnusedTypeVar } from "./eval"; +import { evalEditorBlock, getUnusedTypeVar, type ResolvedType } from "./eval"; import { autoInputWidth } from "./util/dom_trickery"; import "./LambdaBlock.css"; @@ -77,7 +77,10 @@ export function LambdaBlock({state, setState, suggestionPriority}: LambdaBlockPr state={state.expr} setState={setExpr} onCancel={() => setState(state => state.expr)} - suggestionPriority={suggestionPriority} + suggestionPriority={(s) => { + // console.log('suggestionPriority of lambdaInner... just passing through'); + return suggestionPriority(s); + }} />
diff --git a/src/eval.ts b/src/eval.ts index 497a3cd..7e8b3cf 100644 --- a/src/eval.ts +++ b/src/eval.ts @@ -86,9 +86,6 @@ const mergeMaps = (...maps: Map[]) => { export function evalCallBlock2(fnResolved: ResolvedType, inputResolved: ResolvedType, env): ResolvedType { if (getSymbol(fnResolved.t) !== symbolFunction) { - if (fnResolved.kind === "unknown") { - return entirelyUnknown(env); // don't flash everything red, giving the user a heart attack - } // worst outcome: we know nothing about the result! return { kind: "error", @@ -102,8 +99,7 @@ export function evalCallBlock2(fnResolved: ResolvedType, inputResolved: Resolved // fn is a function... const [outType, substitutions] = assignFnSubstitutions(fnResolved.t, inputResolved.t); // may throw - // console.log('assignFn...', prettyT(fnResolved.t), prettyT(inputResolved.t), '\nout =', prettyT(outType), substitutions); - + // console.log('assignFn...', prettyT(fnResolved.t), inputResolved.i, prettyT(inputResolved.t), '\nout =', prettyT(outType), substitutions); const mergedSubstitutions = mergeMaps(substitutions, fnResolved.substitutions, inputResolved.substitutions); @@ -284,12 +280,12 @@ export function attemptParseLiteral(text: string, env): Dynamic[] { export function scoreResolved(resolved: ResolvedType, outPriority: (s:ResolvedType) => number) { const bias = outPriority(resolved); - + if (resolved.kind === "value") { - return 1 + bias; + return 2 + bias; } else if (resolved.kind === "unknown") { - return 0 + bias; + return 1 + bias; } if (resolved.e instanceof UnifyError) { return -1 + bias; // parameter doesn't match