From 186785c7bc7d511fef75ec22e72143f7707ae886 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Mon, 3 Nov 2025 22:08:25 +0100 Subject: resugar evaluated term --- lambda-calcul/haskell/public/repl.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lambda-calcul/haskell/public/repl.js') diff --git a/lambda-calcul/haskell/public/repl.js b/lambda-calcul/haskell/public/repl.js index bd7e743..17be218 100644 --- a/lambda-calcul/haskell/public/repl.js +++ b/lambda-calcul/haskell/public/repl.js @@ -49,13 +49,18 @@ function appendOutput(text) { } }; -function prettyTerm(term) { - if(term.tag === "Var") { +function prettyAST(term) { + if(term.tag === "Sym") { return term.contents; - } else if(term.tag === "Lam") { - return "(lam (" + term.contents[0] + ") " + prettyTerm(term.contents[1]) + ")"; + } else if(term.tag === "Abs") { + return "(lam (" + term.contents[0].join(" ") + ") " + prettyAST(term.contents[1]) + ")"; } else if(term.tag === "App") { - return "(" + prettyTerm(term.contents[0]) + " " + prettyTerm(term.contents[1]) + ")"; + const pref = "(" + prettyAST(term.contents[0]) + " " + prettyAST(term.contents[1]); + if(term.contents[2]) { + return pref + " " + term.contents[2].map(prettyAST).join(" ") + ")"; + } else { + return pref + ")"; + } } return JSON.stringify(term); } @@ -72,7 +77,7 @@ function prettyType(type) { function formatResult(text) { const result = JSON.parse(text); if (result.tag === "Evaluated") { - return prettyTerm(result.contents[0]) + ' : ' + prettyType(result.contents[1]); + return prettyAST(result.contents[0]) + ' : ' + prettyType(result.contents[2]); } else if (result.tag === "Msg" ) { return result.contents; } -- cgit v1.3.1