24
\$\begingroup\$

Say there's a challenge with two inputs. Can we submit a function signature like this?

a=>b=>...

Instead of

(a,b)=>...

The function then becomes callable as f(a)(b) instead of f(a,b), if we provide example usage. Is this considered acceptable, or should it be added to "standard loopholes"?

\$\endgroup\$
7
  • 9
    \$\begingroup\$ I'm really tempted to say "morally, no", but I don't have any actual argument against it. \$\endgroup\$
    – Sp3000
    Commented Feb 15, 2016 at 2:23
  • 13
    \$\begingroup\$ It... feels wrong, but I don't know why. >_> \$\endgroup\$
    – Doorknob Mod
    Commented Feb 15, 2016 at 2:27
  • 2
    \$\begingroup\$ It should be fine, but don't think you can write actual code like this... ;) \$\endgroup\$ Commented Feb 15, 2016 at 2:29
  • 1
    \$\begingroup\$ It is only shorter for dyadic functions. \$\endgroup\$
    – Dennis Mod
    Commented Feb 15, 2016 at 2:31
  • 2
    \$\begingroup\$ We don't have any rules against currying, so I don't see why not \$\endgroup\$
    – user45941
    Commented Feb 15, 2016 at 4:10
  • 5
    \$\begingroup\$ Haskell does this all the time, every function has only one argument. So of course it should be allowed for ES6, too. \$\endgroup\$
    – nimi
    Commented Feb 15, 2016 at 7:07
  • 2
    \$\begingroup\$ I've added a corresponding answer to the list of admissible I/O methods so people don't have to know about yet another meta post. \$\endgroup\$
    – Martin Ender Mod
    Commented Feb 15, 2016 at 7:49

3 Answers 3

24
\$\begingroup\$

Well, yes.

You just have to specify how to call it in your answer. It's no different than a submission that expects a certain type of input input (command line args vs. STDIN, for example).

\$\endgroup\$
1
  • 2
    \$\begingroup\$ As odd as that kind of function definition feels, I think you're right. \$\endgroup\$
    – Alex A. Mod
    Commented Feb 15, 2016 at 2:26
-1
\$\begingroup\$

No.

This is just shifting work to the caller. Taking that to the nth degree, can't you just submit c=>c() to every challenge, explaining that your function needs you to call it with the argument z=>...insert actual code here...?

I don't see any reason why the conventions of function calling in Haskell should affect the conventions of function calling in Javascript.

\$\endgroup\$
-14
\$\begingroup\$

No

My reasoning is that the output is wrong.

If the challenge was:

Take two integers a and b and output the sum of a and b.

and your answer was:

a=>b=>a+b

then your answer is in the form of a function (a=>...), but the output of this function is another function instead of "the sum of a and b".

\$\endgroup\$
6
  • 4
    \$\begingroup\$ Does it return a function if you call it like f(a)(b)? \$\endgroup\$
    – Alex A. Mod
    Commented Feb 15, 2016 at 3:08
  • 4
    \$\begingroup\$ I disagree. You imply that there is a strict way of calling a javascript function; when the code is used in that way, then of course you'll end up with a function. \$\endgroup\$ Commented Feb 15, 2016 at 3:08
  • 4
    \$\begingroup\$ I disagree. If you know lambda calculus, you know that \xy.xy is the same as \x.\y.xy. (If you don't: basically, chaining functions as a=>b=> is the same as (a,b)=>). \$\endgroup\$ Commented Feb 15, 2016 at 3:16
  • \$\begingroup\$ @AlexA. No, it would return the sum when called like f(a)(b), but note that you are actually calling the outer and the inner function which seemed like processing outside of the solution to me. If your answer is the outer function, I feel like you should only be allowed to call the outer function. \$\endgroup\$
    – user81655
    Commented Feb 15, 2016 at 3:20
  • 1
    \$\begingroup\$ I think calling it like f(a)(b) is reasonable so long as its stated that it should be called that way. \$\endgroup\$
    – Alex A. Mod
    Commented Feb 15, 2016 at 3:21
  • 8
    \$\begingroup\$ As nimi noted in a comment on the question, this would actually disallow function submissions in languages like Haskell for any problem that takes multiple arguments, since any multi-argument function is actually a curried single-argument function there. \$\endgroup\$
    – Martin Ender Mod
    Commented Feb 15, 2016 at 7:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .