Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92945 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74748 invoked from network); 29 Apr 2016 16:04:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2016 16:04:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.53 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.53 mail-wm0-f53.google.com Received: from [74.125.82.53] ([74.125.82.53:36157] helo=mail-wm0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/FE-26386-91683275 for ; Fri, 29 Apr 2016 12:04:42 -0400 Received: by mail-wm0-f53.google.com with SMTP id n129so33561739wmn.1 for ; Fri, 29 Apr 2016 09:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=Wm/yXJ415hWNoTORCB1ni2UOmPbpe5Mi/UUUYJhvxhM=; b=b7V4/9N6NVqOVVZESmSkKlLPwCuob+nTZWTOemPtnYYvyfDzrsfABzJVPm4QOv4DMy B7xc2sqaIUB3J/E2XK7x7n6jw/OpFIQqTOKLZxxA+GwAjvYTsB+WJ1xTsdqsef7gk2yx oOoB16hDSPzyPeG+zOHEXr0FegZjVaJV8s13unPUDdy2G78suhbRPgb4lz7Xmkx2MU6i WREgDc1k1OlHq2ok2IM9j3V631U2w5ntdVEZABAgWcOlWbix+PyIWQS6/AS9fh3dK5+E 4r/OOzsKKG6r3SW1vXINUdU7ZV60MYp/uQLBKRSSLIg8Nuj2Zq/ukRI318YaKumiNfjL NU0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=Wm/yXJ415hWNoTORCB1ni2UOmPbpe5Mi/UUUYJhvxhM=; b=WFNtrBuXo8yvT+n1PUfJoEokgK6nfV0pXwm219l9HQYJaQHxQcE9o72C8lEFYJwCBP 4JLQaUrTRoW5N3mDJtFxEg8/zhGtWoN0lk7Iav7S+2aoPMJaaMqLpoCVbbTTVG0qA60z mSATG9oVgexZo1dEs+bsKAiRoFBcpH+CbmqEE7v3S1MXng2gA4bIe/+vDYzsMA3vv9qz hFp6L7/pecDRf/OAlQDTSgsZ1o4q1EnE6P8eZSGXkj84gwb0nzPhLWMJE2NkPKY05l2U RNrrRda/o6knrcp3kcg5+uaJF667KbC9FhDsfOHyqjPDircGckP9hx3IU3QAAxZLrp64 I+Wg== X-Gm-Message-State: AOPr4FWwwdPL5YJfJcET4GLzTeVg7ycQ82vGHV3jHweioPu4mwzwwzF8BRZdmHdZ5cbX0w== X-Received: by 10.28.4.149 with SMTP id 143mr4871794wme.44.1461945878984; Fri, 29 Apr 2016 09:04:38 -0700 (PDT) Received: from [192.168.0.82] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id kj9sm15457750wjb.14.2016.04.29.09.04.38 for (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Apr 2016 09:04:38 -0700 (PDT) To: PHP internals References: <57173859.4080501@rochette.cc> <013101d19ff8$596b6010$0c422030$@tutteli.ch> Message-ID: Date: Fri, 29 Apr 2016 17:02: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) Hi Dominic, Sorry, I think this may have got sent too early by mistake; please ignore the duplicate! Also, it's crossed in the post with your next message, but I'll send it anyway, in case it helps anyone understand. Dominic Grostate wrote on 29/04/2016 16:45: > It's not insane, it's liskov substitution. But that is an insane > example, typical of Java to create a type that extends it's parent by > adding value constraints.. directly violating the principle. Let's translate the covariant example code into English: function addPiToList(List $list): void // "I am a function that accepts any list of Numbers" { $list->add(3.1415); // "To the list I was given, add the Double 3.1415, which is a kind of Number" } $li = new List; // "This is a new list of Integers" addPiToList($li) // "You asked for a list of Numbers; Integers are Numbers, so I can give you my list" So far, so reasonable. But now lets see what gets executed: $list->add(3.1415); // "To the list of Integers you gave me, I will add the Double 3.1415" // "Oops! A Double isn't allowed in your list, I will now produce a Type Error" Now the same with the contravariant List example: function addPiToList(List $list): void // "I am a function that accepts a list of any category, as long as that category includes Doubles" { $list->add(3.1415); // "To the list I was given, add the Double 3.1415" } $ln = new List; // "This is a new list of Numbers, it can mix Integers and Doubles, because they are both types of Number" addPiToList($ln) // "You asked for a list that can contain Doubles; my list can contain any Number, including Doubles, so I can give you my list" And inside the function: $list->add(3.1415); // "To the list of Numbers you gave me, I will add the Double 3.1415" // "Yay, it worked. :)" Contravariance always seems counterintuitive, but it turns out it really is the appropriate constraint in certain situations. Regards, -- Rowan Collins [IMSoP]