Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93974 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42643 invoked from network); 14 Jun 2016 19:53:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jun 2016 19:53:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.44 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.220.44 mail-pa0-f44.google.com Received: from [209.85.220.44] ([209.85.220.44:35651] helo=mail-pa0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DC/E2-27860-AA060675 for ; Tue, 14 Jun 2016 15:53:14 -0400 Received: by mail-pa0-f44.google.com with SMTP id hl6so185951pac.2 for ; Tue, 14 Jun 2016 12:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=w2K9qou8PfWaPYrkwJrcXT+4TDSyBMT7268sV+pg/gg=; b=rL5f/GjWxo0WfZ8dk4Hfyxn4kVZr3blVOWbebrE+os7kCw21ivu2RGXL1oBBk1Ty2+ XLCV2M+8LKuZYBraHUd/Us9rLXGY3bwekhRE71nR/FCn9sVND2d/6q+3PoK5Z2eh87sN CHO89zs5C+31f1x6D8YdHlFgV/jLnYj19UrSnYeWyNcH/emHGLyL56y16kLewwPpRFEF CQW/UZtwzLtRJ+ReJlCv/y9VGkEWLIHjet3voiFf30p/RE+9gNVuJJpz4qRWyJ9iqU6V XJL7FVDPhVhRM6+Lfop9+r7/kBuMTre1nJL+2IXfUIGfun/J0B3K8uRZbSg/y/OOykQ9 NWMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=w2K9qou8PfWaPYrkwJrcXT+4TDSyBMT7268sV+pg/gg=; b=RJIWUgsmZCS+dUbyQeORiQPG9g09I4rp+STlxs7PemRDGinfblQmtK2CZyEHqe8DF4 X4xqtX1B3mo3BnXkpYBAwyuk8KlwlTQ6Mi+7SeRsBuFpSigvUqeDqP93sU+qWgS+Q5jn Shl9eWXH5VLpNRFrJC2mCETZhBtJW1xwidtVKc9roQ269ybvto9wYY/rqUqXMUCjfjS3 tQQdXmLkYJ+ylarnTLjPzmvwpIefRdhLoHbO5N5zEbXuEbWn3+AgwHAd8Veq0woQ0iMK N58NVYYdwJhIRu3H8j66xWj6HhM7XCxlW6KnVRQVdKEwQHv24yf5B/N/QPM4gBJ8cktr wh3g== X-Gm-Message-State: ALyK8tLUn4T/zXuVtBJbSubzVsw0EtqQPjCvU9eEvG2BoqnpwjHu+UEyTxxzX9f2qAy6dzG0v7pDKhUxQDYTpg== X-Received: by 10.66.126.179 with SMTP id mz19mr29808843pab.27.1465933991777; Tue, 14 Jun 2016 12:53:11 -0700 (PDT) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.66.236.137 with HTTP; Tue, 14 Jun 2016 12:53:10 -0700 (PDT) In-Reply-To: <6B3C4F2A-22D6-4004-9F14-5E43EA8AD52A@zend.com> References: <8d26c709-2083-40ac-3bb5-cddc0ecef4bd@gmail.com> <6B3C4F2A-22D6-4004-9F14-5E43EA8AD52A@zend.com> Date: Tue, 14 Jun 2016 13:53:10 -0600 X-Google-Sender-Auth: tqoDF0DWHplujB8P2z2tZOKfcJg Message-ID: To: Zeev Suraski Cc: Stanislav Malyshev , Bob Weinand , PHP internals , Derick Rethans Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] [VOTE] Union types From: levim@php.net (Levi Morrison) > I'm personally against Union types because it makes no sense for classes 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. A Something will return a Something for map, and a Nothing will return a Nothing. By using inheritance there are two problems: 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. 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. 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.