Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92595 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79467 invoked from network); 21 Apr 2016 15:25:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Apr 2016 15:25:31 -0000 Authentication-Results: pb1.pair.com header.from=guilhermeblanco@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=guilhermeblanco@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.172 as permitted sender) X-PHP-List-Original-Sender: guilhermeblanco@gmail.com X-Host-Fingerprint: 209.85.223.172 mail-io0-f172.google.com Received: from [209.85.223.172] ([209.85.223.172:35702] helo=mail-io0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 46/C0-14036-BE0F8175 for ; Thu, 21 Apr 2016 11:25:31 -0400 Received: by mail-io0-f172.google.com with SMTP id d62so660704iof.2 for ; Thu, 21 Apr 2016 08:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=o0ccFXeWPnIPqbD7IBVtEAgnE+Lo5mxx1lfs/PGFMj4=; b=tb7VAE319sVxHcOcfyWedMV3L3FiCh5mwu3laCXZeQS8omjEUassciqkNCTtxcsEvY IyzxKe87G/6ofs35g66emV+1LsaympMvIFVrYFZs3VWvQWQnn48HU2IDoCkCljxQjFQV f137oG2NPCwkSwvkMQ3uIgP+RbMTie6lXd36zXj5BX9s8VbrMX7TyuE8tNeQE6dzO4t1 MtfsrhIimLNuXO9ZGprz0hmdlDQHYQjMW5PBCrtOZ5jl/R747ZO5FJ4kcolnUYDZ0H81 5Dx3J+15mDps7N1vOFmOjuc5vaO4RMbAZRifXY6xipOTby7ZyW6F56gVvJ/2Per3iAKU Rd2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=o0ccFXeWPnIPqbD7IBVtEAgnE+Lo5mxx1lfs/PGFMj4=; b=bxvCIM43mboMjz7iu7upn2qi0xpXMYuapbWTcoa7hP2bkOi24is1AHhA/7vHCctwx3 up3dFiB87qlMzzxR24NUaXPD5GpJEJOVJr448jVzm7+Num0iXcAb+4mL6xQ2oz9rcLrM D94692tIXoTADl+xc2kB5/sd5f2JtduoUeqRqLlxGIpRmiClu15Ht1u9DpIRh9MQ0Uel 2Kq6gSqAaai+WPqmIiClfJsUn9EM6S0+MsRqrPf0mYAv3VtFPaX6pOCiFuUP0FMjYevQ T8a39SjWpQtlb+HwE68PYBFpv7JYE+n2y/jWhFRuDP12GVD0nLVaO8E1g1DskksuhzXl 7Drg== X-Gm-Message-State: AOPr4FUU1h1mjNA8zOVkP3EajgWW00B4kaimX1cAdzPTPaff9SMgnrd3I6y2v85LWfpszTNNnzC3u9gav4p8PQ== X-Received: by 10.107.31.129 with SMTP id f123mr17879091iof.180.1461252327988; Thu, 21 Apr 2016 08:25:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.85.10 with HTTP; Thu, 21 Apr 2016 08:25:08 -0700 (PDT) In-Reply-To: References: <3cc8a4c7-2640-11ae-a67b-06f909ac1e27@texthtml.net> <57173859.4080501@rochette.cc> <57180921.8020000@gmail.com> Date: Thu, 21 Apr 2016 11:25:08 -0400 Message-ID: To: Jesse Schalken Cc: Rowan Collins , PHP internals Content-Type: multipart/alternative; boundary=001a114026deefe1a70531005128 Subject: Re: [PHP-DEV] [RFC:generics] From: guilhermeblanco@gmail.com ("guilhermeblanco@gmail.com") --001a114026deefe1a70531005128 Content-Type: text/plain; charset=UTF-8 I see that some of you are confusing union types with intersecting types here. The idea is not an OR, but an AND. I'll repeat the same example again to try to exemplify what I mentioned: class AA {} interface B {} interface C {} class BB extends AA implements B {} class CC extends AA implements B, C {} class Foo {} class Bar {} Class Foo means an intersecting type, where only class CC is applicable there. Class Bar means a union type, whee both AA, BB and CC are applicable. I understand others mentioned we could create a new interface that wraps the other two interfaces, but that still doesn't solve the problem where I want to extend a class AND also implement a specific interface. Surely this can be a subsequent RFC, but I see that as a deficiency of the currently proposed one and consider it incomplete. What happens if the initial one get approved but it is too late to propose the subsequent one? Then PHP 7.1 would be released with a partial implementation and not fully featured as it should. Regards, On Wed, Apr 20, 2016 at 11:18 PM, Jesse Schalken wrote: > On Thu, Apr 21, 2016 at 8:56 AM, Rowan Collins > wrote: > > > > I'm not quite sure what bounds would mean for anything other than classes > > or interfaces. A generic type that specified that its type parameter must > > be an int seems to me to be a non-generic type, because nothing other > than > > an int "is int". How is "class Foo { public function > > __construct(T $arg) { ... } }" different from just saying "class Foo { > > public function __construct(int $arg) { ... } }"? (Unless there were some > > kind of overloading, such that you could also have Foo, but > > please let's not go there...) > > > > Sticking with your example for a moment, if the type parameter is an "int", > then the only type that can *currently* be expressed in the type language > that is a subtype of "int" is "int", so it's not very useful *right now*. > However, a possible introduction of integer literal types would change > that, especially in combination with unions. This would enable you to > express the type "1|2|3", i.e. only one of those three integers. This would > be useful to typecheck enums, which are typically an "int" or "string" > which only accepts a finite set of values. As such, the type parameter "T > is int" could be filled with "int" or "1" or "0|1|2". (Imagine a class > "Bar" and various subclasses which each must select a single > integer as kind of tag, "Foo extends Bar<1>", "Baz extends Bar<2>" etc. I > do this in TypeScript with string literal types all the time.) > > Beside from that, the introduction of any one of union types, intersection > types, generic array types or callable types would mean the type constraint > for a generic type can usefully be something besides a single > class/interface. For example, if "" were written > "" I would expect to be able to do "$t > instanceof array|Traversable", but I wouldn't be able to unless > "instanceof" is intended to and is extended to support arbitrary types. > > Note that generic arrays are out of scope of the current RFC anyway, so > > it's possible that "$t instanceof array" could be added at the same > > time as "Foo>", presumably with the meaning that > > "array" would be considered to pass the check. > > > > Regards, > > > > -- > > Rowan Collins > > [IMSoP] > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- Guilherme Blanco Lead Architect at E-Block --001a114026deefe1a70531005128--