On Fri, May 14, 2021 at 2:49 PM Aaron Piotrowski <aa...@trowski.com> wrote:
>
> Consider `function foo(int $x, int $y, int $z) {}` with a partial defined as 
> `$partial = foo(?, 42)`.
>
> If the partial is called as `$partial(73, 8)`, should 8 be forwarded to `$z` 
> or should the call error as providing too few arguments?

The 8 passes along to $z. There is no error, all required arguments
have been provided.

> Or perhaps should the partial declaration should error, as it should have 
> been `foo(?, 42, ?)` or `foo(?, 42, ...?) so the partial provided all 
> required arguments to foo.

I think this highlights where the misunderstanding of this feature is.
Partial application is about binding arguments. ? isn't an argument,
it's an argument placeholder. It does two things: signals to create a
closure wrapping the function rather than calling it immediately, and
holds a position in the argument list so that an argument further to
the right can be fixed (bound) at that time. Arguments are bound;
argument placeholders are not, they exist only for convenience. The
syntax `foo(?, 42)` doesn't call foo, let alone provide any arguments
to it, it simply creates a closure that'll pass along 42 at the
appropriate argument position along with whatever else it's provided
with.

Requiring additional trailing argument placeholders or adding an
additional token `...?` unnecessarily complicates things, burdens the
user, and only serves to further promote misunderstanding.


>
> Cheers,
> Aaron Piotrowski
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to