News for hackers. Stuff that matters.
Re:Node.js - A giant step backwards? by ufo on Friday January 27, 2012 @07:39AM (#3518041)
Pure code can be used in the monad just fine, (ie.: you can return values up to the monad and lift functions)

    //turn a function into a monadic action
    function lift(f){ return function(/**/){
        var d = new Deferred(); //Im using the Dojo API
        d.resolve( f.call(this, arguments) );
        return d.promise;
    };};
    
    var f = function(x){ return x+1}
    
    lift(f)(0)
    .then(function(y){ ... })
The problem is the opposite direction: pure code using monadic code and pure code turning into monadic code

If you have something like

    var x = f1( f2( f3() ) )
And f2 becomes a monadic action you have to rewrite this bit as

    var xPromise = f2( f3() )
    .then(function(f2result){
        return f1(f2result);
    });
Re:Node.js - A giant step backwards? by freshhawk on Sunday January 29, 2012 @02:56PM (#3526004)
ah, very nice, it is easy. The chaining is still fairly clunky though, although maybe comparing it to haskell's do notation syntactic sugar is unfair.

(isn't the opposite direction the feature of doing things this way? That you can't call monadic code from pure code is a good thing)