Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73837 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33897 invoked from network); 29 Apr 2014 01:20:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2014 01:20:01 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.50 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.219.50 mail-oa0-f50.google.com Received: from [209.85.219.50] ([209.85.219.50:53892] helo=mail-oa0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/40-29159-04EFE535 for ; Mon, 28 Apr 2014 21:20:00 -0400 Received: by mail-oa0-f50.google.com with SMTP id i11so8222290oag.9 for ; Mon, 28 Apr 2014 18:19:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=o1Z+XtjcMBjdQCf0zEACPJTyg0ePwZPKuganmvVrABQ=; b=gh6N4xK+mqZpKuee+TY98SlDNdOGkkjWQxcvtxcKyzxTcgh4F4J1i5OEQaZbj+HJS+ jq5D2dCFJdmP9WSHp73RfY/NYxtT1ToQ0GPNuCkBlVc4HwhiVzBEsRUyEGbKpsz79YqW LKHHVsOrP0fFpE3kjbEcq/YtPahpJF7Nff5rJX5Gfyu7ZAojF4zWgb6014/E3YLZ5UHU zzZs8XOKw+CHa6O8sVX575MkIfgoysZiXy+QzGtqGYfRao/xsMb5Y1AgYkh/nLSq8Wd0 aJGMmICRZ4YumeThvTBPukvFPriOhtbbBppyHSMpCmC8NGC7+TWaSfUiKXGRRDPh2CN/ MqiQ== MIME-Version: 1.0 X-Received: by 10.182.22.33 with SMTP id a1mr52267obf.60.1398734397201; Mon, 28 Apr 2014 18:19:57 -0700 (PDT) Received: by 10.76.77.100 with HTTP; Mon, 28 Apr 2014 18:19:57 -0700 (PDT) In-Reply-To: <535ECB9E.5050701@garfieldtech.com> References: <535E9AED.2080904@garfieldtech.com> <535ECB9E.5050701@garfieldtech.com> Date: Mon, 28 Apr 2014 19:19:57 -0600 Message-ID: To: Larry Garfield Cc: internals Content-Type: multipart/alternative; boundary=001a1133177ce163f604f8243a5d Subject: Re: [PHP-DEV] [RFC] Return Type Declarations From: morrison.levi@gmail.com (Levi Morrison) --001a1133177ce163f604f8243a5d Content-Type: text/plain; charset=UTF-8 On Mon, Apr 28, 2014 at 3:43 PM, Larry Garfield wrote: > On 4/28/14, 3:30 PM, Levi Morrison wrote: > > As I write that I suspect it's because generators actually "return" an >>> interator object, and so the return type of the generator is being >>> interpreted relative to the construction, not iteration, of the >>> generator. >>> That seems like a likely source of confusion, as I would, as a >>> developer, >>> expect to be specifying the type that gets returned from iteration, not >>> from construction, so that my foreach loop (or similar) can rely on the >>> type being returned. >>> >>> >> The type hint is purposefully not the type of the value returned; a >> generator always returns a generator. I will clarify this in the RFC and >> maybe adjust the wording in the error message as well to better indicate >> this. >> > > So I suppose technically we should say that a generator must always return > a Traversable? Not quite: a generator always returns a Generator (this is an actual object); so it can fulfill Generator, Iterator and Traversable. > > I think this part warrants further consideration. The rest of the RFC I >>> fully look forward to using. >>> >> >> Special casing a generator's return type would be an inconsistency in the >> design. If you var_dump() something that returns generator it tells you it >> is a generator; this should match the type of the return value and >> anything >> else is unexpected. As an example, using a generator to fulfill an >> Iterator >> return type should succeed; special casing the Generator would complicate >> the code to achieve this. Special casing the generator would also infringe >> on other future ideas, such as adding generics to the language. All in >> all, >> special casing generators doesn't make sense. >> > > That makes sense from an engine point of view, certainly. From a user > POV, I can still see it being the source of much confusion. I confess I've > barely used generators so far (PHP 5.5 still having very small market > penetration), but it feels natural to mentally align return type / return > keyword and return type / yield keyword. It also means I have no way of > declaring that a generator will always return items of type X, which seems > like a valid thing to do. Agreed; however I would rather have all kinds of Iterators and collection like object be able to type their values too. This would obviously fall outside of this RFC so I have specifically left this possibility open without directing its future too much. --001a1133177ce163f604f8243a5d--