On 30/01/2017 17:55, Levi Morrison wrote:
Bob Weinand and I are happy to announce that the [Arrow Functions][1]
RFC is moving into the public discussion phase. We have been
collaborating on this RFC for many months now and finally have a
proposal we are happy to discuss in the open.
[1]: https://wiki.php.net/rfc/arrow_functions
Firstly, I like this proposal a lot more than the previous, so thank you
for working on this based on previous discussion. In particular, I'm
glad to see it focused on single expressions with implicit return, as I
think that's where it has most value.
A few comments:
ThisRFC does support type declarations for parameters and return types.
An example of the syntax for this would be good, particularly how the
return type fits the syntax (which may conflict with my suggestion below).
The implementation currently supports static closures, for example |static fn($x)
=> static::get($x)|.
I was initially confused by this paragraph, because I was unaware that
static closures existed. I'm still not entirely sure *why* they exist,
but for anyone else wondering, here's what they currently look like:
http://php.net/manual/en/functions.anonymous.php#functions.anonymous-functions.static
Finally, my personal preference is still for a syntax that encloses the
whole definition somehow, and since we need the fn keyword anyway, I
wonder about stretching the brackets around the whole definition, e.g.
fn($x => $x * 2).
Personally, I find this:
->reduce(fn($tmp, $v => $tmp + $v), 0)
easier to mentally parse than this:
->reduce(fn($tmp, $v) => $tmp + $v, 0)
because you only have to match brackets to see where the ", 0" belongs.
I also think it would make combining closures clearer if they were
nested rather than associative (I guess those used to reading Haskell
will probably disagree with me):
$complement = fn($f) => fn(... $args) => !$f(... $args)
vs
$complement = fn($f => fn(... $args => !$f(... $args)))
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php