Skip to content

Commit

Permalink
Fixed list comprehension, no longer uses monad desugar
Browse files Browse the repository at this point in the history
  • Loading branch information
phyrex1an committed May 31, 2010
1 parent c3f6d07 commit c9ecb8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
21 changes: 12 additions & 9 deletions haskell.ast.js
Expand Up @@ -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)));
};


Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions hs/Prelude.hs
Expand Up @@ -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


Expand Down

0 comments on commit c9ecb8a

Please sign in to comment.