[PHP-DEV] [RFC] Disjunctive Normal Form Types

  117379
March 19, 2022 16:38 george.banyard@gmail.com ("G. P. B.")
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
  117380
March 19, 2022 16:46 zsidelnik@gmail.com (Eugene Sidelnyk)
Looks very interesting, and most importantly, useful.

On Sat, Mar 19, 2022 at 6:38 PM G. P. B. 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 >
  117381
March 19, 2022 17:15 sandfox@sandfox.me (Anton Smirnov)
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
  117392
March 21, 2022 17:00 pollita@php.net (Sara Golemon)
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
  117387
March 21, 2022 02:42 internals@lists.php.net ("Levi Morrison via internals")
> 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!
  117911
June 12, 2022 10:13 george.banyard@gmail.com ("G. P. B.")
On Sat, 19 Mar 2022 at 16:38, G. P. B. 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