Browse files

Limited version of :t

  • Loading branch information...
1 parent f72b29c commit c9de206c42dcc6384aabe085795a0bbc811136db @phyrex1an phyrex1an committed May 29, 2010
Showing with 12 additions and 8 deletions.
  1. +11 −7 haskell.hiji.js
  2. +1 −1 haskell.typechecker.js
View
18 haskell.hiji.js
@@ -104,6 +104,7 @@ commands[":type"] = "TYPE";
}
input.attr("value","");
+ $('.input', this).replaceWith(makeEntered(modules, line));
if(isCommand(line)){
runCommand(line, input, line);
}else
@@ -114,13 +115,12 @@ commands[":type"] = "TYPE";
printArea = $("ol", this);
env = evaluateHaskell(line, env);
console.log("%o", env);
- $('.input', this).replaceWith(makeEntered(modules, line));
- $("ol",this).append(makeInput(modules));
}
catch(e) {
console.log("%o", e);
};
}
+ $("ol",this).append(makeInput(modules));
//set focus
$("input:text:visible:first").focus();
@@ -214,11 +214,15 @@ commands[":type"] = "TYPE";
$("ol").append(makeInput(modules));
} else if (commands[command] == "TYPE") {
var arg = trim(input.substr(command.length));
- var ast = haskell.parser.parse(arg).ast;
- var type = ast.infer(/* some env */);
- var newLine = ast.stringify() + " :: " + type.stringify();
- $('.input').after(output).replaceWith(newLine);
- $("ol").append(makeInput(modules));
+ var ast = haskell.parser.parse('{' + arg + '}').ast.expr;
+ var tc = haskell.typechecker;
+ var infered = ast.infer(new tc.Environment(new tc.Assumps(), new tc.Subst(), new tc.NameGen()));
+ var predsString = infered.preds.map(function(p) { return p.toString(); }).join(", ");
+ if (predsString.length > 0) {
+ predsString = "(" + predsString + ") => ";
+ }
+ var newLine = ast.stringify() + " :: " + predsString + infered.type.toString();
+ $("ol").append(makeOutput(newLine));
}
}
};
View
2 haskell.typechecker.js
@@ -663,7 +663,7 @@
return this.type().hnf();
};
this.toString = function() {
- return this.id() + " => " + this.type();
+ return this.id() + " " + this.type();
};
};

0 comments on commit c9de206

Please sign in to comment.