# [RFC] Disjunctive Normal Form Types

- Thread: https://externals.io/message/117379
- Original archive: https://news-web.php.net/php.internals/117379
- Started by G. P. B. on 2022-03-19T16:38:43+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #117379 — G. P. B. — 2022-03-19T16:38:43+00:00

URL: https://externals.io/message/117379#117379

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 — Eugene Sidelnyk — 2022-03-19T16:46:05+00:00

URL: https://externals.io/message/117379#117380 · In reply to: #117379

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_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 — Anton Smirnov — 2022-03-19T17:15:28+00:00

URL: https://externals.io/message/117379#117381 · In reply to: #117379

> 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

---

## #117387 — Levi Morrison via internals — 2022-03-21T02:42:15+00:00

URL: https://externals.io/message/117379#117387 · In reply to: #117379

> 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!

---

## #117392 — Sara Golemon — 2022-03-21T17:00:28+00:00

URL: https://externals.io/message/117379#117392 · In reply to: #117381

> 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

---

## #117911 — G. P. B. — 2022-06-12T10:13:39+00:00

URL: https://externals.io/message/117379#117911 · In reply to: #117379

> 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
