Curried functions

Isiah Meadows isiahmeadows at gmail.com
Fri Oct 16 06:59:36 UTC 2015


I also prefer explicit currying and partial application, since it's
easier to reason about types. I would rather not deal with
transparent, keyword-only currying, since it can eventually become
hard to debug because it can get confusing as to how many parameters
are left before application. It's especially the case with dynamically
typed languages.

On Fri, Oct 16, 2015 at 1:27 AM, Bob Myers <rtm at gol.com> wrote:
> It's trivially simply to write a function `currify` which essentially does
> what your proprosed `curry` keyword does.
>
> ```js
> function currify(f) {
>   return function _currify(flen, _f) {
>     return (...args) => {
>       var remaining = flen - args.length;
>       return remaining <= 0 ?
>         _f(...args) :
>         _currify(remaining, (...args2) => _f(...args, ...args2));
>     };
>   }(f.length, f);
> }
>
>
> function add(a, b, c) { return a + b + c; }
> var _add = currify(add);
>
> console.log(_add(1)(2)(3));
> console.log(_add(1, 2)(3));
> console.log(_add(1)(2, 3));
> console.log(_add(1, 2, 3));
> ```
>
> --
> Bob
>
>
>
> On Fri, Oct 16, 2015 at 1:15 AM, Michael McGlothlin
> <mike.mcglothlin at gmail.com> wrote:
>>
>> I dislike that syntax because it makes the order of operations mysterious.
>> I like the idea of currying but it should always be clear what is going on.
>> A couple parentheses would make things a lot more obvious.
>>
>> On Thu, Oct 15, 2015 at 8:02 AM, Mark S. Miller <erights at google.com>
>> wrote:
>>>
>>> const add = a => b => a + b;
>>>
>>>
>>> On Thu, Oct 15, 2015 at 8:08 AM, Niloy Mondal <niloy.mondal84 at gmail.com>
>>> wrote:
>>>>
>>>> It would be really cool to have syntax to curry functions built into the
>>>> languages. Something like...
>>>>
>>>> ```js
>>>> curry function add(a, b) {
>>>>     return a + b;
>>>> }
>>>>
>>>> add(2)(3); // 5
>>>>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
Isiah Meadows


More information about the es-discuss mailing list