Should an expression evaluating to a function count as a function for the purpose of providing a solution when a function is asked for? An earlier question on meta seems to indicate a consensus that it is fine to provide a function literal when "a function" is asked for.
Many languages treat functions as first-class citizen, and allow operations on functions such as composition or binding variables. What I wonder is if such expressions that evaluate to a function should be acceptable as an answer.
To illustrate the difference, below is an example of an explicit and a point-free function in Haskell, both yielding the same result.
\xs -> map succ xs -- explicit ("function literal")
map succ -- point-free (partial application due to currying)
-- both behave the same
(\xs -> map succ xs) [1,2,3] -- evaluates to [2,3,4]
(map succ) [1,2,3] -- evaluates to [2,3,4]
This seems sufficiently different than the linked question to deserve one on its own. So, what do you think?
(map succ)
would be considered a function, whilemap succ
is an expression. \$\endgroup\$f=map succ
and have a named function at the same cost in most languages (a notable exception being J, where it's one character more expensive) \$\endgroup\$f=map succ
works too. \$\endgroup\$map succ
is that it's a function that is only ever used once, for one input, to produce one output. Fundamentally, an expression is just a function that is only ever used once, for one input, to produce one output. Hence a point-free/anonymous function is semantically equivalent to an expression, and expressions aren't allowed in code golf challenges that ask for functions. That's just my take on it. \$\endgroup\$