jashkenas/coffee-script — pull request #2202 by shf (2012-03-20 00:25:52+00:00)
Title: Haskell-ish left arrow operator, async callbacks

Hello!

This is just a proof of concept for this idea I had. It's a bit like IcedCoffeeScript, but instead of using async/defer, it uses the `<-` operator to turn sequential code into CPS, just like Haskell. I think it looks "cleaner" and fits more with the rest of CoffeeScript, plus, `<-` makes a lot of sense, since it's the opposite of `->` ;)

This is nowhere as advanced as @maxtaco 's fork, and the code quality isn't that good, but here it goes...

So, it turns this:

test = ->
id = (v,f) ->
f(v)
a <- id(1)
b <- id(a)
c <- id(b)
console.log(c)

Into this (generated by CoffeeScript):

(function() {
var test;

test = function() {
var id;
id = function(v, f) {
return f(v);
};
id(1, function(a) {
id(a, function(b) {
id(b, function(c) {
return console.log(c);
});
});
});
};

test();

}).call(this);

As I said, it's not production-quality code. Particularly, the algorithm that searches and replaces nodes downward on node.coffee is hack-ish and has a lot of duplication (the getSiblings should be on Base), but I wanted to keep it short, so...

Oh, you have to rebuild the parser for it to work, btw...

So, what do you folks think? Yay? Nay? Way too close to monad-land?

Thanks!