summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/public
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell/public')
-rw-r--r--lambda-calcul/haskell/public/repl.js17
1 files changed, 11 insertions, 6 deletions
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;
}