Re: [PHP-DEV] [Discussion] Revisiting typed closures

[email protected] (Seifeddine Gmati)
Newsgroups php.internals
Message-ID <CAFyg4HgPSHFhKR1YpPkLaTXN-wSTvFU267m-Vrg9UqvWXi9WAw@mail.gmail.com>
> I would rather wait for generics and possibly make Closure a generic type.
>
> — Rob

Hi Rob,

I don't think generics help here. PHP doesn't have generics at all
yet, and realistically they're at least a couple of years away. But
even once they land, they wouldn't solve this.

Making `Closure` generic (e.g., say `Closure<Input, Output>` ) would
require `Input` to be variadic to stand in for a closure's parameter
list, and variadic generics are a different beast entirely.

They've never appeared in any proposal, they don't really make sense
for a number of reasons, and if they were ever added at all, it would
be years after generics themselves. So "wait for generics" here
effectively means waiting indefinitely. And arity aside, a generic
`Closure<...>` still couldn't express which arguments are required
versus optional, nor type a closure that is itself generic. A
dedicated syntax like `fn<T>(T, string=): T` handles all of it
cleanly:

- The generic parameter ( `<T>` )
- Te required and optional arguments ( `=` marker )
- The return type ( following `:` )

Cheers,
Seifeddine
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.