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
Looks very interesting, and most importantly, useful.
Hello internals,
I would like to open the discussion on the Disjunctive Normal Form (DNF)
types RFC:
https://wiki.php.net/rfc/dnf_typesThe 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
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:
-
I think that syntax would be cleaner without the parentheses
-
[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
- 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
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!