Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93980 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53462 invoked from network); 14 Jun 2016 20:43:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jun 2016 20:43:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.82 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.82 blu004-omc2s7.hotmail.com Received: from [65.55.111.82] ([65.55.111.82:53113] helo=BLU004-OMC2S7.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/15-27860-A7C60675 for ; Tue, 14 Jun 2016 16:43:39 -0400 Received: from BLU436-SMTP22 ([65.55.111.73]) by BLU004-OMC2S7.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Tue, 14 Jun 2016 13:43:35 -0700 X-TMN: [2KrUUVH94/sjb1io9HDawyndu0bO5EjR] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_04F9AECC-8FB5-46EA-BBE4-8821A7A0065E" MIME-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: Date: Tue, 14 Jun 2016 22:43:31 +0200 CC: Zeev Suraski , Stanislav Malyshev , PHP internals , Derick Rethans References: <8d26c709-2083-40ac-3bb5-cddc0ecef4bd@gmail.com> <6B3C4F2A-22D6-4004-9F14-5E43EA8AD52A@zend.com> To: Levi Morrison X-Mailer: Apple Mail (2.2070.6) X-OriginalArrivalTime: 14 Jun 2016 20:43:33.0404 (UTC) FILETIME=[6AB6EDC0:01D1C67D] Subject: Re: [PHP-DEV] [RFC] [VOTE] Union types From: bobwei9@hotmail.com (Bob Weinand) --Apple-Mail=_04F9AECC-8FB5-46EA-BBE4-8821A7A0065E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" > Am 14.6.2016 um 21:53 schrieb Levi Morrison : >=20 >> I'm personally against Union types because it makes no sense for = classes >=20 > I've been over this before but I'll repeat it here for completeness: > this is not true. Unions provide a way to discriminate between > potential sets of types. Even among classes there is power in unions. > Consider the idea of encoding a Something or Nothing with methods such > as `map`, `flatmap`, `filter`, etc. >=20 > A Something will return a Something for map, and a Nothing will return > a Nothing. By using inheritance there are two problems: >=20 > 1. We can create additional subclasses that do not obey the > semantics of the type. Imagine how frustrating a stack that does not > behave like a stack would be; same principle here. > 2. We don't have covariant return types so we cannot express that > Nothing::map will return Nothing and Something::map will return > Something. >=20 > Using two final classes for Something and Nothing and then doing a > union on them has neither of these downsides. Even if we add return > type covariance we cannot solve problem 1. >=20 > Given that there are numerous other uses with built-in types such as > Array | Traversable (iterable), int | string (array key), int | float > (numeric) and so forth it does not make sense to me to special case > these things. Generality is better for language features than special > casing. What Levi tries to explain: unions are like a temporary virtual = super-interface to any accepted class without actually being implemented = by them. Typically you are writing adapters for these things, but an adapter is = not always the solution (i.e. in cases where a part of the handling is = identical, but depending on the actual class (instanceof) they = ultimately get dispatched to somewhere else). For exactly these cases (which, I admit, aren=E2=80=99t numerous [The = cases where it=E2=80=99s legitimate and there is no other superior = solution]) union classes are helpful. Bob --Apple-Mail=_04F9AECC-8FB5-46EA-BBE4-8821A7A0065E--