[RFC] Disjunctive Normal Form Types

php.internals

Girgias

4 years ago
Hello internals, I would like to open the discussion on the Disjunctive Normal Form (DNF) types RFC: https://wiki.php.net/rfc/dnf_types The implementation for it is available on my fork, [1] but currently relies on a pending PR [2] to make the implementation simpler. DNF types are a way to mix intersection and union types together in a single type. For example: - (A&B)|null - (Traversable&Countable)|array Best regards, George P. Banyard [1] https://github.com/Girgias/php-src/pull/10 [2] https://github.com/php/php-src/pull/7309

[ ]

4 years ago
Looks very interesting, and most importantly, useful. On Sat, Mar 19, 2022 at 6:38 PM G. P. B. <george.banyard@gmail.com> wrote:

Anton Smirnov

4 years ago
On Sat, 2022-03-19 at 16:38 +0000, G. P. B. wrote:
> DNF types are a way to mix intersection and union types together in a > single type. > For example: >  - (A&B)|null >  - (Traversable&Countable)|array
Hello George, I like your proposal. I would like to offer 2 suggestions however: 1. I think that syntax would be cleaner without the parentheses 2. [Future Scope] I would go against non-DNF types. DNF forms a nice two level structure that's easy to comprehend. Arbitrary expressions may be too much for runtime checks (correct me if I'm wrong) and will definitely have high cognitive complexity. And CNF would allow to form invalid types too easily like (Traversable|null)&Countable Best, Anton

Sara Golemon

4 years ago
On Sat, Mar 19, 2022 at 12:15 PM Anton Smirnov <sandfox@sandfox.me> wrote:
> 1. I think that syntax would be cleaner without the parentheses > >
No. https://c.tenor.com/zM15ZrNYp0QAAAAM/no-michael-scott.gif Grouping is never cleaner without parenthesis than it is with them. The actual proposal? Yes. DNF types as the next step in complex type expressions. -Sara

Unnamed Person

4 years ago
> DNF types are a way to mix intersection and union types together in a > single type. > For example: > [...] > - (Traversable&Countable)|array
I have yet to read the fine print, but this example was a motivating case for me to start down the union-types road years ago. I would be very happy to finally see this in the language!

Girgias

4 years ago
On Sat, 19 Mar 2022 at 16:38, G. P. B. <george.banyard@gmail.com> wrote:
> Hello internals, > > I would like to open the discussion on the Disjunctive Normal Form (DNF) > types RFC: > https://wiki.php.net/rfc/dnf_types > > The implementation for it is available on my fork, [1] but currently > relies on a pending PR [2] to make the implementation simpler. > > DNF types are a way to mix intersection and union types together in a > single type. > For example: > - (A&B)|null > - (Traversable&Countable)|array > > Best regards, > > George P. Banyard > > [1] https://github.com/Girgias/php-src/pull/10 > [2] https://github.com/php/php-src/pull/7309 >
I would like to open voting on this during the week now that the pending PR has been merged and the implementation is mostly done (modulo some OpCache changes and edge cases to test) PR: https://github.com/php/php-src/pull/8725 If there are any concerns or things to address now is the time. Best regards, George P. Banyard