diff --git a/src/component/app/App.tsx b/src/component/app/App.tsx index e49c3f5..f01a7ec 100644 --- a/src/component/app/App.tsx +++ b/src/component/app/App.tsx @@ -8,6 +8,8 @@ import { biggerExample, emptySet, factorial, higherOrder, higherOrder2Params, in import './App.css'; import { evalExpr } from '../../eval/eval'; +import { Value } from '../other/Value'; +import { Type } from '../other/Type'; const examples: [string, ExprBlockState][] = [ @@ -182,7 +184,13 @@ export function App() { }} typeInfo={typeInfo} /> - ={evalExpr(currentState, extendedEnv)} + = + + :: + diff --git a/src/component/other/Type.tsx b/src/component/other/Type.tsx index ee0198d..6a8bb59 100644 --- a/src/component/other/Type.tsx +++ b/src/component/other/Type.tsx @@ -1,8 +1,13 @@ import { getHumanReadableName, getSymbol, symbolDict, symbolDictIterator, symbolFunction, symbolList, symbolProduct, symbolSet, symbolSetIterator, symbolSum } from "dope2"; import "./Type.css"; +import { ValueUnknown } from "./Value"; export function Type({type}) { + if (type === undefined) { + // Types are just values, and sometimes, when using a Type as a Value, the Type is unknown (e.g., because of an eval error when computing the type) + return ; + } const symbol = getSymbol(type); switch (symbol) { case symbolFunction: diff --git a/src/component/other/Value.css b/src/component/other/Value.css index edb375c..7c82c7b 100644 --- a/src/component/other/Value.css +++ b/src/component/other/Value.css @@ -16,4 +16,8 @@ margin-right: 2px; padding-left: 2px; padding-right: 2px; +} + +.valueUnknown { + color: darkgrey; } \ No newline at end of file diff --git a/src/component/other/Value.tsx b/src/component/other/Value.tsx index d708f8f..eebde7c 100644 --- a/src/component/other/Value.tsx +++ b/src/component/other/Value.tsx @@ -1,4 +1,4 @@ -import {getType, getInst, getSymbol, Double, Int, symbolFunction, symbolProduct, symbolSum, symbolDict, symbolSet, symbolList, eqType, match, getLeft, getRight, dict, Bool, set, Unit, symbolType, symbolUUID, getHumanReadableName, Ordering} from "dope2"; +import {getType, getInst, getSymbol, Double, Int, symbolFunction, symbolProduct, symbolSum, symbolDict, symbolSet, symbolList, eqType, match, getLeft, getRight, dict, Bool, set, Unit, symbolType, symbolUUID, getHumanReadableName, Ordering, isTypeVar} from "dope2"; import "./Value.css"; import { Type } from "./Type"; @@ -6,6 +6,11 @@ import { Type } from "./Type"; export function Value({dynamic}) { const type = getType(dynamic); const inst = getInst(dynamic); + if (inst === undefined) { + // Sometimes we only know the type of a value, not the value itself. + // For instance, if there is an evaluation error somewhere. + return ; + } if (eqType(type)(Double)) { return ; } @@ -87,4 +92,7 @@ function ValueUUID({val}) { } function ValueOrdering({val}) { return {{[-1]: "LessThan", [0]: "Equal", [1]: "GreaterThan" }[val]} +} +export function ValueUnknown() { + return unknown } \ No newline at end of file diff --git a/src/eval/eval.ts b/src/eval/eval.ts index df2c7e7..0eb4955 100644 --- a/src/eval/eval.ts +++ b/src/eval/eval.ts @@ -49,7 +49,10 @@ export function evalCall(s: CallBlockState, env: DynamicEnvironment): EvalResult const fn = evalExpr(s.fn, env); const input = evalExpr(s.input, env); if (fn !== undefined && input !== undefined) { - return fn(input); + try { + return fn(input); + } + catch {} } }