From 6ef423e2b2a32b5eca00d354283b1ce312129608 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Mon, 3 Nov 2025 20:04:17 +0100 Subject: better representation of evaluated terms in UI --- lambda-calcul/haskell/public/repl.js | 24 ++++++++++++++++++++++-- 1 file 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; } -- cgit v1.3.1