Permalink
Browse files

declarations. hiji also won't choke on exceptions thrown by typechecker

  • Loading branch information...
1 parent 9a6249e commit 9201606a789484c244f18f9d13f59ff37bbcf7f7 Mattis Jeppsson committed Jun 1, 2010
Showing with 369 additions and 31 deletions.
  1. +24 −17 haskell.hiji.js
  2. +345 −14 haskell.typechecker.js
View
@@ -212,29 +212,36 @@ commands[":type"] = "TYPE";
// $('.input').after(output).replaceWith(newLine);
// $('.input').after(output).replaceWith(newLine);
$("ol").append(makeInput(modules));
+
} else if (commands[command] == "TYPE") {
var arg = trim(input.substr(command.length));
var ast = haskell.parser.parse('{' + arg + '}').ast.expr;
var tc = haskell.typechecker;
var env = new tc.Environment(new tc.Assumps(), new tc.Subst(), new tc.NameGen());
- var infered = ast.infer(env);
- var type = infered.type.apply(env.getSubst());
- var predsSubst = infered.preds.map(function(p) { return p.apply(env.getSubst())});
- var preds = tc.unique(predsSubst.filter(
- function (p) {
- return tc.any(
- p.tv(),
- function(t) {
- return tc.elem(type.tv(), t);
- }
+ var newLine = "";
+ try {
+ var infered = ast.infer(env);
+ var type = infered.type.apply(env.getSubst());
+ var predsSubst = infered.preds.map(function(p) { return p.apply(env.getSubst())});
+ var preds = tc.unique(predsSubst.filter(
+ function (p) {
+ return tc.any(
+ p.tv(),
+ function(t) {
+ return tc.elem(type.tv(), t);
+ }
);
- }
- ));
- var predsString = preds.map(function(p) { return p.toString(); }).join(", ");
- if (predsString.length > 0) {
- predsString = "(" + predsString + ") => ";
- }
- var newLine = ast.stringify() + " :: " + predsString + type.toString();
+ }
+ ));
+ var predsString = preds.map(function(p) { return p.toString(); }).join(", ");
+ if (predsString.length > 0) {
+ predsString = "(" + predsString + ") => ";
+ }
+ newLine = ast.stringify() + " :: " + predsString + type.toString();
+
+ } catch (x) {
+ newLine=x;
+ }
$("ol").append(makeOutput(newLine));
}
}
Oops, something went wrong.

0 comments on commit 9201606

Please sign in to comment.