Skip to content
Browse files

show hack and pretty printing for lists

  • Loading branch information...
1 parent 2dba2fa commit ffa3a01d748a69c74f080ec51c5d336e3395d448 Johan Gustafsson committed May 17, 2010
Showing with 46 additions and 5 deletions.
  1. +46 −5 haskell.hiji.js
View
51 haskell.hiji.js
@@ -98,11 +98,52 @@ commands[":help"] = "HELP";
try {
var newLine = makeEntered(modules, line);
- var result = evaluateHaskell(line, env);
- if (result.force) {
- result = result.force();
- } else if (result.ptrs) {
- result = result.ptrs[0].thunk.force();
+ var showResult = function(result) {
+ if (result.type == "Data") {
+ var str = result.identifier;
+ var op = " ";
+
+ if (str == "I#") {
+ str = "";
+ } else if (str == ":") {
+ str = "";
+ op = ",";
+ }
+
+ if (result.ptrs) {
+ var first = true;
+ for (var i = 0; i < result.ptrs.length; i++) {
+ if (str.length == 0 && first) {
+ str = showResult(result.ptrs[i].dereference());
+ if (str.str)
+ str = str.str;
+ first = false;
+ } else {
+ var res = showResult(result.ptrs[i].dereference());
+ if (res.str)
+ res = res.str;
+ str = str + op + res;
+ }
+ }
+ }
+
+ return { str: str, isList: op == "," };
+ } if (result.force) {
+ return result.force();
+ } else if (result.ptrs) {
+ return result.ptrs[0].dereference();
+ } else {
+ return result;
+ }
+ }
+
+ var result = showResult(evaluateHaskell(line, env));
+ if (result.isList) {
+ result = result.str;
+ result = result.substring(0, result.length - 3);
+ result = "[" + result + "]";
+ } else if (result.str) {
+ result = result.str;
}
var output = makeOutput(result);

0 comments on commit ffa3a01

Please sign in to comment.
Something went wrong with that request. Please try again.