From ebae0afc812fc23299d8b5439ef3313b7e4dd9e1 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Mon, 12 May 2025 11:11:18 +0200 Subject: [PATCH] more progress --- pnpm-lock.yaml | 8 ++++---- src/CallBlock.css | 21 +++++++++++++++++++++ src/CallBlock.tsx | 34 ++++++++++++++++++++++++++++++---- src/InputBlock.css | 4 +++- src/InputBlock.tsx | 4 ++-- src/Value.css | 2 +- src/Value.tsx | 42 +++++++++++++++++++++++++++++++++--------- 7 files changed, 94 insertions(+), 21 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab03867..b1e9c27 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,7 +10,7 @@ importers: dependencies: dope2: specifier: git+https://deemz.org/git/joeri/dope2.git - version: git+https://deemz.org/git/joeri/dope2.git#d531c48a9298f318d089b900009f32cb9f04a53a + version: git+https://deemz.org/git/joeri/dope2.git#a9e21d7d94a7c75c34a95116931b458507131694 react: specifier: ^19.1.0 version: 19.1.0 @@ -633,8 +633,8 @@ packages: resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} engines: {node: '>= 0.8'} - dope2@git+https://deemz.org/git/joeri/dope2.git#d531c48a9298f318d089b900009f32cb9f04a53a: - resolution: {commit: d531c48a9298f318d089b900009f32cb9f04a53a, repo: https://deemz.org/git/joeri/dope2.git, type: git} + dope2@git+https://deemz.org/git/joeri/dope2.git#a9e21d7d94a7c75c34a95116931b458507131694: + resolution: {commit: a9e21d7d94a7c75c34a95116931b458507131694, repo: https://deemz.org/git/joeri/dope2.git, type: git} version: 0.0.1 dunder-proto@1.0.1: @@ -1758,7 +1758,7 @@ snapshots: depd@2.0.0: {} - dope2@git+https://deemz.org/git/joeri/dope2.git#d531c48a9298f318d089b900009f32cb9f04a53a: + dope2@git+https://deemz.org/git/joeri/dope2.git#a9e21d7d94a7c75c34a95116931b458507131694: dependencies: functional-red-black-tree: 1.0.1 diff --git a/src/CallBlock.css b/src/CallBlock.css index 1611057..40127b0 100644 --- a/src/CallBlock.css +++ b/src/CallBlock.css @@ -4,9 +4,18 @@ margin: 1px; } +.functionBlock.unifyError { + /* background-color: pink; */ + /* color:white; */ +} + .functionName { /* text-align: center; */ + background-color: white; +} +.functionBlock.unifyError .functionName { + /* background-color: pink; */ } @@ -43,3 +52,15 @@ /* border-radius: 10px; */ width: 100%; } + +.functionBlock.unifyError .inputParam { + background-color: darkred; + color: white; +} +.functionBlock.unifyError .inputParam:after { + border-left-color: darkred; +} + +.functionBlock.unifyError .outputParam { + background-color: pink; +} \ No newline at end of file diff --git a/src/CallBlock.tsx b/src/CallBlock.tsx index bd164f6..ab404ce 100644 --- a/src/CallBlock.tsx +++ b/src/CallBlock.tsx @@ -1,9 +1,9 @@ -import { apply, getType, getInst } from "dope2"; +import { apply, getType, getInst, assignFn, UnifyError } from "dope2"; import type { Dynamic, State2Props } from "./util/extra"; import { Editor, type EditorState } from "./Editor"; import "./CallBlock.css"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { Type } from "./Type"; import { Value } from "./Value"; import { focusPrevElement } from "./util/dom_trickery"; @@ -22,6 +22,7 @@ interface CallBlockProps extends State2Props { } export function CallBlock({ state: {kind, env, fn, input, resolved, rollback }, setState, onResolve }: CallBlockProps) { + const [unifyError, setUnifyError] = useState(undefined); const setResolved = (resolved?: Dynamic) => { setState({kind, env, fn, input, resolved, rollback}); } @@ -35,9 +36,16 @@ export function CallBlock({ state: {kind, env, fn, input, resolved, rollback }, onResolve({ kind, env, fn, input, resolved: outputResolved, rollback }); + setUnifyError(undefined); } catch (e) { - console.log('makeTheCall:', e); + if (!(e instanceof UnifyError)) { + throw e; + } + setUnifyError(e); + onResolve({ + kind, env, fn, input, resolved: undefined, rollback + }) } } @@ -84,7 +92,21 @@ export function CallBlock({ state: {kind, env, fn, input, resolved, rollback }, } } - return + const filterCompatibleInputs = ([_name, dynamic]: [string, Dynamic]) => { + if (fn.resolved) { + try { + assignFn(getType(fn.resolved), getType(dynamic)); + } catch (e) { + if (!(e instanceof UnifyError)) { + throw e; + } + return false; + } + } + return true; + } + + return
𝑓𝑛  : <> } + { unifyError + ? <>{unifyError.toString()} + : <> + }
; diff --git a/src/InputBlock.css b/src/InputBlock.css index 7115fd4..a458fbf 100644 --- a/src/InputBlock.css +++ b/src/InputBlock.css @@ -16,6 +16,7 @@ } .suggestions { display: none; + color: black; } .suggestions { display: block; @@ -24,7 +25,7 @@ border: solid 1px dodgerblue; cursor: pointer; max-height: calc(100vh - 44px); - overflow: scroll; + overflow: auto; z-index: 10; background-color: white; } @@ -52,6 +53,7 @@ font-variation-settings: "wdth" 100; background-color: transparent; + color: inherit; } .border-around-input { border: 1px solid black; diff --git a/src/InputBlock.tsx b/src/InputBlock.tsx index 8b9835f..f7d5777 100644 --- a/src/InputBlock.tsx +++ b/src/InputBlock.tsx @@ -19,7 +19,7 @@ export interface InputBlockState { } interface InputBlockProps extends State2Props { - filter: (ls: any[]) => boolean; + filter: (suggestion: [string, Dynamic]) => boolean; onResolve: (state: InputBlockState) => void; onCancel: () => void; } @@ -120,7 +120,7 @@ export function InputBlock({ state: {kind, env, text, resolved, rollback}, setSt e.preventDefault(); }, ArrowUp: () => { - setI((i - 1) % suggestions.length); + setI((suggestions.length + i - 1) % suggestions.length); e.preventDefault(); }, ArrowLeft: () => { diff --git a/src/Value.css b/src/Value.css index 6d539a7..33a1068 100644 --- a/src/Value.css +++ b/src/Value.css @@ -1,4 +1,4 @@ -.value { +.valuePrimitive { border: 1px solid black; border-radius: 10px; margin-left: 2px; diff --git a/src/Value.tsx b/src/Value.tsx index a58aab1..8e05bed 100644 --- a/src/Value.tsx +++ b/src/Value.tsx @@ -1,4 +1,4 @@ -import {getType, getInst, getSymbol, Double, Int, symbolFunction, symbolProduct, symbolSum, symbolDict, symbolSet, symbolList, eqType, match, getLeft, getRight} from "dope2"; +import {getType, getInst, getSymbol, Double, Int, symbolFunction, symbolProduct, symbolSum, symbolDict, symbolSet, symbolList, eqType, match, getLeft, getRight, dict} from "dope2"; import "./Value.css"; @@ -11,6 +11,7 @@ export function Value({dynamic}) { if (eqType(type)(Int)) { return ; } + const symbol = getSymbol(type); switch (symbol) { case symbolFunction: @@ -20,10 +21,13 @@ export function Value({dynamic}) { // return ; case symbolSum: return ; - case symbolProduct: - return ; + + case symbolProduct: + return ; - // case symbolDict: + case symbolDict: + return ; + // return ; // case symbolSet: // return ; @@ -36,10 +40,10 @@ export function Value({dynamic}) { } function ValueDouble({val}) { - return {val.toString()}; + return {val.toString()}; } function ValueInt({val}) { - return {val.toString()}; + return {val.toString()}; } function ValueFunction() { return <>𝑓𝑛 ; @@ -52,9 +56,29 @@ function List({val, elemType}) { } function ValueSum({val, leftType, rightType}) { return match(val) - (l => <>L ) - (r => <>R ); + (l => L ) + (r => R ); } function ValueProduct({val, leftType, rightType}) { - return <>(); + return (); +} +function ValueDict({val, keyType, valueType}) { + let i=0; + return {'{'}<>{ + dict.fold + (acc => key => value => { + console.log({acc, key, value}); + return acc.concat([<> + + ⇒ + + ]); + }) + ([]) + (val) + .map(result => { + console.log(result); + return result; + }) + }{'}'}; } \ No newline at end of file