On 13/12/2021 23:12, Kirill Nesmeyanov wrote:
> I'll add that leading optional parameters are needed to implement currying and partial application.
>
> ```
> function foo(int $opt = 42, int $req) {}
>
> $foo = curry(foo(...), 23);
>
> // $foo = fn($opt = 42, $req = 23);
> ```
I'm confused what the optional parameter is doing here - is it just to
avoid telling the curry function which argument you're fixing? And
wouldn't both currying and partial application result in a
single-argument closure there, not just making both parameters optional?
I would expect it to look something like this:
```
function foo(int $a, int $b) {}
$foo = partial(foo(...), 23, 0);
// $foo = fn($b) => foo(23, $b);
$foo = partial(foo(...), 23, 1);
// $foo = fn($a) => foo($a, 23);
$bar = curry(foo(...));
// $bar = fn($a) => fn($b) => foo($a, $b);
```
> While this is not a popular practice in PHP, this deprecation notification «breaks» all code that uses functional pradigm/concepts.
That's clearly an exaggeration; it's clearly possible to write
functional-style code without making use of this particular trick. If it
is a *common* trick, then that's worth considering, but it would be good
to see some evidence of that.
Regards,
--
Rowan Tommins
[IMSoP]