Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92587 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41691 invoked from network); 21 Apr 2016 03:18:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Apr 2016 03:18:34 -0000 Authentication-Results: pb1.pair.com header.from=jesseschalken@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jesseschalken@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.173 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.213.173 mail-ig0-f173.google.com Received: from [209.85.213.173] ([209.85.213.173:34983] helo=mail-ig0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D3/5C-14036-A8648175 for ; Wed, 20 Apr 2016 23:18:34 -0400 Received: by mail-ig0-f173.google.com with SMTP id gy3so146316575igb.0 for ; Wed, 20 Apr 2016 20:18:34 -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:date:message-id:subject :from:to:cc; bh=w98UELjtPtZNLQ8UGmZISMgyKjmeW1uvc2HS2WY7ZC8=; b=wswrEzg7/2Lq+NLcOvSoKFb+FsMgpWydVD1qXTwDk0SeuSIn6toFcTH8k+m445BU1H XW/pfztag/aXd37RUVMMDVnTINNAnUGoxbOe3Kz3QGUD2BtfALmYzGXvFI6qr0ydS81f cmGadWzlvu1+TCypaQ21O3FiQ5Anqk913JGCpLI9Gr6IYhRflsnry7l5bES4EOREf2dx 05fJgWyZv8lJIQS6VN7gcGSWYv6P8u+NtYlpIiZmGY/l62ysD+ROAjBciGcfqBp4/NXT tedFOkZ50T9gqfpcfxW8CoBjVa887RiRK+tIxncpS1Culq3P9xVCVj4kwsUA9EVkHRUf o5pg== 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:date :message-id:subject:from:to:cc; bh=w98UELjtPtZNLQ8UGmZISMgyKjmeW1uvc2HS2WY7ZC8=; b=YioyrPNW2rwbHahAgDZEv2zK3Rm9jG4EfbXrzG1+poGRhhKD7WJMRU4wRB3fzvhlxG tcx/BaXuKBzpIu47m3lyI0QJeivUpWjCRqCBG7Aawp9RDkyNZKDRQ0oChBEPuaF3x+KQ zsudKrAJwWN/OwmiAfeKNu/ctuVeiNEvKfUJU2mlzCfW084dTU7hNZf2jJmNkV18A+Mr OayiH2VNQP5tIcq00iGnKYfts8WrZUmAKrcPENuNXp1jGyNRFvZ+TanI6wpvoSz/YM/j 5ngctNR0vTOzkEIFihBm6M75x5QQsxbqWJlJRu/Pp7k7YbO6ntW88zpYj3pwM/eYqP/e g9pg== X-Gm-Message-State: AOPr4FXU8Nb7Dp9LATQ3IX0KkRH83xaATT6x/2T0ddTrWbCURbR3beX/j+L5RNEEW1ptEGZfMtQYv3O90A/yhw== MIME-Version: 1.0 X-Received: by 10.50.228.171 with SMTP id sj11mr746088igc.55.1461208711921; Wed, 20 Apr 2016 20:18:31 -0700 (PDT) Sender: jesseschalken@gmail.com Received: by 10.79.139.133 with HTTP; Wed, 20 Apr 2016 20:18:31 -0700 (PDT) In-Reply-To: <57180921.8020000@gmail.com> References: <3cc8a4c7-2640-11ae-a67b-06f909ac1e27@texthtml.net> <57173859.4080501@rochette.cc> <57180921.8020000@gmail.com> Date: Thu, 21 Apr 2016 13:18:31 +1000 X-Google-Sender-Auth: 5QBLd90wwps30ymRpix4gMZHJTE Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=f46d04289df73787b30530f62a65 Subject: Re: [PHP-DEV] [RFC:generics] From: me@jesseschalken.com (Jesse Schalken) --f46d04289df73787b30530f62a65 Content-Type: text/plain; charset=UTF-8 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 > > --f46d04289df73787b30530f62a65--