Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92554 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65240 invoked from network); 20 Apr 2016 15:43:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 15:43:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=codekestrel@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=codekestrel@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 74.125.82.44 as permitted sender) X-PHP-List-Original-Sender: codekestrel@googlemail.com X-Host-Fingerprint: 74.125.82.44 mail-wm0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:38367] helo=mail-wm0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/DE-14036-EA3A7175 for ; Wed, 20 Apr 2016 11:43:43 -0400 Received: by mail-wm0-f44.google.com with SMTP id u206so88458303wme.1 for ; Wed, 20 Apr 2016 08:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=qjEQissRTDtOamZgaooZS4eajZPvbQxysbFJ1jkPCH8=; b=swaGwzxvE7MMHMeUs+T0o8KLonQHax6xnxO7GFTb4LnCFF/DmB6WRSWV3WiaXAiifg NE2EINwwbNWa3UMW69ePYWhzITx3VsfBbl9PpFrlMelGu/kdbyHwZpycrQU8G3tB8K1A /QZSuol+RMElOpcN+BaIVopukM8Nzt31e6iW1sj1ScWJWSbiwTgrXA7MzH6TkRIugrV8 miCwx6uYI+ngAeHcWQt+6861b7PgkifBjHCVX1ZrFakL5eCSZsXE5oKsy+xR3iEvrYlL ZMMMEILjTn8hbQFam/PjJu3iwuJFT/Bgj3eIGfAkuYvTPaWysd5yWfkIkBYghTWYCPxT UhRw== 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:date :message-id:subject:from:to:cc; bh=qjEQissRTDtOamZgaooZS4eajZPvbQxysbFJ1jkPCH8=; b=f/2zlac1yukmB6pQjz0YhEA9geXudSuis9XkHePgl+e2t6qIigistXmjDHHY05spm2 ceERo76ZU9vd6CN0CiG28WDZJAP2K3BeXrkKDhbKb3pF/oRj5WZk3y75IgwB8cDCnEw1 uvX8mIdvI24TegJnErii0w/QV8kG5MZmhOogruCJRQ6/10ldSSk8JPfbfwYKZLW6sQWs Hi3uK78aiEXB1n3B5gtqc7AAhs2qSbd21HRzL7lP6sxlUJS34t4xQXNobzMF6N8K7avf YVM+D6TuSO34lUEsvcVPyCi/SNetg7+AuCBI6cyQr3hmFe8g3tItFEkDU0d/ryFPxAbe bizQ== X-Gm-Message-State: AOPr4FUkqMi2UT0fKn/sQ0+GZcw4ypBE8vxx9U5x/X+0+k9ZPU5O8CV7pChwJSYbT5hpcNs1oNFD4p6h05Y/Hw== MIME-Version: 1.0 X-Received: by 10.194.115.196 with SMTP id jq4mr9328292wjb.101.1461167020264; Wed, 20 Apr 2016 08:43:40 -0700 (PDT) Received: by 10.28.140.10 with HTTP; Wed, 20 Apr 2016 08:43:40 -0700 (PDT) Received: by 10.28.140.10 with HTTP; Wed, 20 Apr 2016 08:43:40 -0700 (PDT) In-Reply-To: References: <3cc8a4c7-2640-11ae-a67b-06f909ac1e27@texthtml.net> <57173859.4080501@rochette.cc> Date: Wed, 20 Apr 2016 16:43:40 +0100 Message-ID: To: guilhermeblanco@gmail.com Cc: Mathieu Rochette , Josh Di Fabio , "Ben Scholzen 'DASPRiD'" , Sara Golemon , PHP internals , Rasmus Schultz , Mathieu Rochette Content-Type: multipart/alternative; boundary=001a1130cd7c3393c00530ec755a Subject: Re: [PHP-DEV] [RFC:generics] From: codekestrel@googlemail.com (Dominic Grostate) --001a1130cd7c3393c00530ec755a Content-Type: text/plain; charset=UTF-8 I agree on both points (technically). It would allow you to apply that restriction. I only advise against it to reduce the impact the initial implementation would have on the codebase, provided it is preferable to implement it in phases. As for inference. Rasmus and I have argued over that a fair bit, as I was in favour of using 'new Entry<>' or just 'new Entry' to be a parameterised type with no type constraints (any value). On 20 Apr 2016 3:44 p.m., "guilhermeblanco@gmail.com" < guilhermeblanco@gmail.com> wrote: > I don't know if mid-thread answering may lead to top-posting, but if it > does, I'm sorry... =\ > > Answer inline: > > On Wed, Apr 20, 2016 at 5:10 AM, Dominic Grostate < > codekestrel@googlemail.com> wrote: > >> I've made an amendment to the RFC to clarify on the Nested Types, which is >> indeed supposed to be part of the feature. Rasmus may want to reword it >> if >> it isn't very clear. >> >> Regarding union and intersections for upper (and maybe lower) bounds. >> Would it be appropriate to exclude these from type parameters until their >> respective RFCs are approved? As including them in generics but not in >> standard type hints may create an inconsistency. >> >> In short, perhaps a generics implementation should incorporate unions (and >> any future type constraints) as existing features only. This would help >> RFC Generics to focus on: Type aliasing, Introspection and Reflection. >> > > Unions and Intersections are required anyway, and I don't see how you can > implement generics without supporting them. > Let's say I'm implementing a cache library that segregate the interface of > BulkOperations from the basic operations named CacheDriver. > In a given class, I might want to only accept CacheDrivers that also > support BulkOperations. How would I achieve that? > > The same happens to upper bounds that someone asked for an example > privately. > If I want to hire/move a person to a department that is registered in the > system, but is not a 3rd party company person, how would you achieve that > considering the following class structure? > > class Person {} > class Employee extends Person {} > class AssociateEmployee extends Employee {} > class Manager extends Employee {} > > Considering your function: > > function assignToDepartment(T $person) : bool; > > Generic type "T" in the function prototype needs to accept Person (new > hire), Employee and Manager (transfer), but not AssociateEmployee. > Considering upper bounds support only, your best bet is "T extends Person", > but that would accept AssociateEmployee to be provided, which contradicts > the business rule. Accepting anything lower in the hierarchy prevents new > hires. > That's when lower bounds comes into play. If you define as "T super > Manager", all Person, Employee and Manager gets accepted, but not the > AssociatedEmployee, matching properly the business rule. > > > Also, someone else asked about type inference over my comment #4 in this > example: > > class Foo { > public function __construct(B $b) {} > } > > $foo = new Foo(1); > > The question asked is if that "string" was an inference over A or B. The > correct answer is A, because generic type B is inferred from the parameter > (integer) provided. That is exactly why class generic type definition > should never be inferred from the constructor arguments, because you make > it impossible to support both constructor generic types AND class generic > type definitions at the same time. > > > >> On 20 Apr 2016 9:05 a.m., "Mathieu Rochette" wrote: >> >> > >> > >> > On 20/04/2016 00:22, Sara Golemon wrote: >> > >> >> On Tue, Apr 19, 2016 at 1:16 PM, Mathieu Rochette < >> mathieu@texthtml.net> >> >> wrote: >> >> >> >>> about the upper bounds, have you consider another way of describing >> the >> >>> constraints, eg: >> >>> >> >>> class Box where T is Boxable >> >>> >> >>> this would allow multiple constraints, eg: >> >>> >> >>> class Collection where T is Traversable, T is Countable >> >>> >> >>> IMO, this sort of problem should be solved by combining this feature >> >> with union types, so you could have something like: >> >> >> >> class Collection {... >> >> >> >> And merely inherit the logic rules from that feature rather than >> >> inventing yet another one. >> >> >> > obviously if the union type rfc passes we don't need another way of >> > expressing this. >> > that was only in the case it does not, I think having a way to have at >> > least types intersection >> > is useful here (and I didn't event think about ) >> > >> >> >> >> can generic types be nested ? >> >>> >> >>> class Stuff> >> >>> >> >>> I can't imagine why not... >> >> >> > just to be clear, it's not just nested generic. the A type have to be >> same >> > in both "subtypes" >> > >> >> >> >> For my part, I love the concept overall. Generics are an important >> >> part of moving PHP towards comprehensive type-safety. But then, you >> >> know how I feel about Hack. :) >> >> >> >> -Sara >> >> >> >> >> > >> > > > > -- > Guilherme Blanco > Lead Architect at E-Block > --001a1130cd7c3393c00530ec755a--