summaryrefslogtreecommitdiff
path: root/lambda-calcul
diff options
context:
space:
mode:
authorArnaud Bailly <arnaud@pankzsoft.com>2025-11-03 20:04:17 +0100
committerArnaud Bailly <arnaud@pankzsoft.com>2025-11-03 20:04:17 +0100
commit6ef423e2b2a32b5eca00d354283b1ce312129608 (patch)
tree53c47317d8efc8eeb085ccc7a6ff9173b29f1cc1 /lambda-calcul
parentee9b0f357d959a8306fab36ebea6ee1efeb1c70e (diff)
downloadlambda-nantes-6ef423e2b2a32b5eca00d354283b1ce312129608.tar.gz
better representation of evaluated terms in UI
Diffstat (limited to 'lambda-calcul')
-rw-r--r--lambda-calcul/haskell/public/repl.js24
1 files changed, 22 insertions, 2 deletions
diff --git a/lambda-calcul/haskell/public/repl.js b/lambda-calcul/haskell/public/repl.js
index 1d4453f..a99494a 100644
--- a/lambda-calcul/haskell/public/repl.js
+++ b/lambda-calcul/haskell/public/repl.js
@@ -49,10 +49,30 @@ function appendOutput(text) {
}
};
+function prettyTerm(term) {
+ if(term.tag === "Var") {
+ return term.contents;
+ } else if(term.tag === "Lam") {
+ return "(lam (" + term.contents[0] + ") " + prettyTerm(term.contents[1]) + ")";
+ } else if(term.tag === "App") {
+ return "(" + prettyTerm(term.contents[0]) + " " + prettyTerm(term.contents[1]) + ")";
+ }
+ return JSON.stringify(term);
+}
+
+function prettyType(type) {
+ if(type.tag === "TyVar") {
+ return type.contents;
+ } else if(type.tag === "TyArr") {
+ return "(" + prettyType(type.contents[0]) + " -> " + prettyType(type.contents[1]) + ")";
+ }
+ return JSON.stringify(type);
+}
+
function formatResult(text) {
const result = JSON.parse(text);
- if (result.rendered) {
- return result.rendered;
+ if (result.tag === "Evaluated") {
+ return prettyTerm(result.contents[0]) + ':' + prettyType(result.contents[1]);
} else if (result.tag === "Msg" ) {
return result.contents;
}