Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I see the first three concepts used interchangeably (as far as I understand)...

Either you misunderstood, or the people using them misunderstood.

Lambdas are anonymous functions. In javascript terminology:

    _.map(someNumbers, function (x) { return x +1; } /* <- lambda */)
Closures are a way of hiding state (or at least data) in anonymous functions:

    makeCounter() {
        var x = 0; 
        function numCalls() { return x++; }; <---the variable x is "closed over"
        return numCalls;
    }
Monads are a method of encapsulation, with goals similar to object orientation. OO is about hiding data inside objects, whereas monads are about hiding most of the outside world from your functions.


And it is important to remember that all functions in JavaScript can (and some say "should") be defined this way.

    var c = 2;
    var f = function (x) { return (2 * x); };
    var g = function (h, x) { return h(x); };




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: