Hacker News new | ask | show | jobs
by lloyd-christmas 2958 days ago
> with some (considerable) effort

disclaimer: I haven't read the book and am not sure if this is mentioned anywhere.

What helped me when thinking about functional design in javascript was realizing that all js functions actually only have one parameter, an array of arguments used by the caller:

    function add(x, y) {
        return x + y;
    }
is effectively syntactic sugar for

    function add() {
        const x = arguments[0];
        const y = arguments[1];
        return x + y;
    }
`add(1,2,3,4)` ignores 3 and 4 instead of being an error. While seemingly obvious that these two functions would have different definitions: `add1(1)(2)` and `add2(1,2)`, thinking about it in types helped me process it when thinking out how they are actually written:

    add1 :: [Number] -> [Number] -> Number
    add2 :: [Number, Number] -> Number
1 comments

Yes. This is the essence of currying.