summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/public/repl.js
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell/public/repl.js')
-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;
}