Permalink
Browse files

Fixed list comprehension, no longer uses monad desugar

  • Loading branch information...
1 parent c3f6d07 commit c9ecb8aa3ffaeed68774344a5105e5ad122b88a9 @phyrex1an phyrex1an committed May 31, 2010
Showing with 15 additions and 11 deletions.
  1. +12 −9 haskell.ast.js
  2. +3 −2 hs/Prelude.hs
View
@@ -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
@@ -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 c9ecb8a

Please sign in to comment.