Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92951 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86480 invoked from network); 29 Apr 2016 16:54:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2016 16:54:44 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.46 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.46 mail-wm0-f46.google.com Received: from [74.125.82.46] ([74.125.82.46:37942] helo=mail-wm0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F6/11-26386-2D193275 for ; Fri, 29 Apr 2016 12:54:43 -0400 Received: by mail-wm0-f46.google.com with SMTP id g17so45966225wme.1 for ; Fri, 29 Apr 2016 09:54:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:references:from:to:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=vY6pKlNSnrJgrz70ivIUanWIJfi0s3CxUgY+dvAA1UA=; b=u+33bKmSQDvjkgzAdVstcIV79ZZiicr7bnz8UPTNY/O14P25+jN52MQ9nPR7iJkZV6 CLeIh3sNdx4p2pT3jjAA3kXVuExZtNsg8JWKeyP6ru5UF2AEbuSYZzvcnysIhs64Vaox nx72tYAetAGXq6fpP9eBkbSCqeBdoBswMDxMgKBsuLXBrWZRhxJJFpbnloDDATwgDF3w UOC258a9zuBldDywWvfyIOq8+MZ/O7D4hFJJtDqw3hiI6pnNl5ZGNwW5XLlXbumbqTU4 AKKDFOJCJNiYtIs813bDPtBMTBjY9uZvv9pvEdiMuFrzGm7hYscm+DI2I0DR/t7GkIIa JLkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:references:from:to:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=vY6pKlNSnrJgrz70ivIUanWIJfi0s3CxUgY+dvAA1UA=; b=ccUyy+wKWc1uPV9YKZevXx4NYmLymwKppAQQgB9FoBCzDRrAR8XOpwRUo+Q2EB5kuP doiRghX7+eV6AfD6hCIbe+GXpLrJtrHGjqwcSvq1giHh6pyk2adw5kSn6DW9m0ir7hiP iL1F32239EwA3iAZ+OEFnxLZP2f9Xtf4/ha42p5DrwJlEVxhqA0BjNVJPuMLDEv4uAUN A2igUDZt3NuNt+bktJibco550hQ/OCLmbIOF27rmOVe4zRE2CsGPZuCrwRmbjOhuCVyK wEw/553p4vZc/GtL/4KN/CY+ZlqaAz6E/brKj5E/zO0pgepCTSevetamb8J7b3/8Rx40 2VqQ== X-Gm-Message-State: AOPr4FWX3woN7aryt6Pr8QaOzsmBjCFbNM3xM2t5k53Yp3ysQFHG650ZKacA6c4tH89t5g== X-Received: by 10.28.10.196 with SMTP id 187mr5356440wmk.76.1461948879201; Fri, 29 Apr 2016 09:54:39 -0700 (PDT) Received: from [192.168.0.82] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id gt7sm15637745wjc.1.2016.04.29.09.54.38 for (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Apr 2016 09:54:38 -0700 (PDT) References: <013101d19ff8$596b6010$0c422030$@tutteli.ch> To: PHP internals Message-ID: <38b9c701-748b-0d0e-7ad6-a01b6f414bcc@gmail.com> Date: Fri, 29 Apr 2016 17:52:14 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC:generics] From: rowan.collins@gmail.com (Rowan Collins) Dominic Grostate wrote on 29/04/2016 17:45: > > This means then that to use a subtype for the type argument, it is > safe for the function to READ the argument, but unsafe to WRITE to it. > > Conversely. If the function accepted List, but was > theoretically given List, WRITING would be safe, but READING > wouldn't. > Precisely. If you read the blog post linked earlier [1], that's exactly how they describe it. > Given this, it doesn't matter how it's done, both scenarios are prone > to error, and the only options are to either accept that or disallow it. > The only safe *default* is to disallow it. However, for a particular implementation, you as the author may know that you are only ever going to write to a particular parameter, and can therefore safely allow that parameter to be "too broad"; or you may know that you are only ever going to read from it, so can safely allow it to be "too narrow". This requires extra syntax in the language, and is fiddly to use right, so should probably be left out of the first implementation and considered later. This is exactly what Hack did, adding a class-level annotation of <+T> or <-T> for read-only or write-only parameters, respectively, to their existing implementation. [1] http://hhvm.com/blog/9215/covariance-contravariance-and-super-type-constraints Regards, -- Rowan Collins [IMSoP]