Skip to content
Browse files

Merge branch 'master' of github.com:johang88/haskellinjavascript

  • Loading branch information...
2 parents 9201606 + 30d35b5 commit 962da9dce497f02c63635f0bc8c8b74f369c32e6 Mattis Jeppsson committed Jun 1, 2010
Showing with 16 additions and 12 deletions.
  1. +12 −9 haskell.ast.js
  2. +1 −1 haskell.interpreter.js
  3. +3 −2 hs/Prelude.hs
View
21 haskell.ast.js
@@ -341,11 +341,11 @@
ast.ListComprehension.prototype = new ast.Expression();
ast.ListComprehension.prototype.desugar = function() {
if (this.notations.length == 0) {
- return (new ast.Application(new ast.VariableLookup("return"), this.ret));
+ return (new ast.Application(new ast.Application(new ast.VariableLookup(":"), this.ret), new ast.VariableLookup("[]")));
}
var first = this.notations[0];
- return new ast.Do([first.partDesugar(), new ast.DoExpr(new ast.ListComprehension(this.ret,
- this.notations.slice(1)))]);
+ return first.partDesugar(new ast.ListComprehension(this.ret,
+ this.notations.slice(1)));
};
@@ -445,9 +445,11 @@
this.expr = expr;
};
ast.ListGuard.prototype = new ast.ListNotation();
- ast.ListGuard.prototype.partDesugar = function() {
- return new ast.DoExpr(new ast.Application(new ast.VariableLookup("guard"),
- this.expr));
+ ast.ListGuard.prototype.partDesugar = function(rest) {
+ return new ast.Application(new ast.Application(new ast.VariableLookup("concatMap"),
+ new ast.Lambda(new ast.Wildcard(), rest)),
+ new ast.Application(new ast.VariableLookup("guard"),
+ this.expr));
};
ast.ListBind = function(pattern, expr) {
@@ -458,9 +460,10 @@
this.expr = expr;
};
ast.ListBind.prototype = new ast.ListNotation();
- ast.ListBind.prototype.partDesugar = function() {
- // x <- expr ==> x <- expr ...
- return new ast.DoBind(this.pattern, this.expr);
+ ast.ListBind.prototype.partDesugar = function(rest) {
+ return new ast.Application(new ast.Application(new ast.VariableLookup("concatMap"),
+ new ast.Lambda(this.pattern, rest)),
+ this.expr);
};
ast.ListLet = function(decls) {
View
2 haskell.interpreter.js
@@ -258,7 +258,7 @@
for (var j in matchedFunc.expression) {
var guard = matchedFunc.expression[j][0];
var expression = matchedFunc.expression[j][1];
- var guardResult = guard.eval(newEnv);
+ var guardResult = (new interpreter.HeapPtr(new interpreter.Closure(newEnv, guard))).dereference();
if (guardResult.identifier == "True") {
return new interpreter.Closure(newEnv, expression);
}
View
5 hs/Prelude.hs
@@ -117,12 +117,13 @@ return a = IO a
fail _ = []
-guard True = return undefined
+-- But Monad Zero is for list monad...
+guard True = [undefined]
guard False = mzero
-
mzero = []
+
undefined = undefined

0 comments on commit 962da9d

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