Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92942 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70167 invoked from network); 29 Apr 2016 15:58:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2016 15:58:07 -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.66 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.66 mail-wm0-f66.google.com Received: from [74.125.82.66] ([74.125.82.66:36083] helo=mail-wm0-f66.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/ED-26386-E8483275 for ; Fri, 29 Apr 2016 11:58:07 -0400 Received: by mail-wm0-f66.google.com with SMTP id w143so5947991wmw.3 for ; Fri, 29 Apr 2016 08:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=BTd3sBSku/aDvSHHeEyouakeNA++tro/T60RcoQq7VQ=; b=d/v/tNfjOK4NKxaAuQMkSYazUmFFHxV4Ktmt5G1VTlzMHAzBjQNrM7WMHoR0Ma0IxC YN1C8ICB/hlLxP0aD/hhi71S1T2pq54Wil2CnZJTzBrV9cMPz+rYUs5T0HDNMNHLRULG vVaHlN5/8zRZx7Vd9yH4uM2K5gaowO3NsIDFbbUKSp7K0vjUSQolPZAyrQ7ENejJV9XR b1tKin1IKMzL6ikw8EocJF01GDnNJjfY9ysp45eeOGWDcDcXYszLrYO45HqXZDt1eBKq Vgc2JJzFU3Uw+Cf5V1XnmpFRqy2vXFXmvKzwzZ85MGEauU8P1xYJj2CYd9SbiwQfgdBF krag== 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:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=BTd3sBSku/aDvSHHeEyouakeNA++tro/T60RcoQq7VQ=; b=abVthj3+MMifljnqQbx4JiD1zzFRwsK9teci7dUvGFP9ypXRxXIsRUq2Nfeyf+CCb7 vsnd06qpHp0LMw5F3rsofiK2VsqRlG2yCRKMH8i3Wd0ulXOe4qMZdoyJttMMAPLrlqxW Q8OVhTw1XUKI3mJAigipRT9D4n4d90WhgBEj/jlh+zgYH8WIT7s4EZOQ5rFStXCAZKkS o8g8d9FyqmOg8Y2HOBAA8R/fJ7Kp1Tp+j5cX+V+5UTabRQs0CiulTlzG0hr/KqteqtF6 /8f0B3EEq6sO9JO4CBtaylqcdA4Dy786CbnLVcE5atKCm8lYcCa2Z+j/dKNMq2dpOQhz D3sQ== X-Gm-Message-State: AOPr4FWdIKTHW307It5LiWyX+7IqrXQB5DtDA5+oFfkPz/jBtCpQiuWKKZMTPxKFCexEMA== X-Received: by 10.28.30.148 with SMTP id e142mr4807812wme.69.1461945484404; Fri, 29 Apr 2016 08:58:04 -0700 (PDT) Received: from [192.168.0.82] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id jd4sm14957535wjb.43.2016.04.29.08.58.03 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Apr 2016 08:58:03 -0700 (PDT) To: Dominic Grostate References: <57173859.4080501@rochette.cc> <013101d19ff8$596b6010$0c422030$@tutteli.ch> Cc: PHP internals Message-ID: <322c217f-902c-51aa-47e1-8449ff3c491d@gmail.com> Date: Fri, 29 Apr 2016 16:55:39 +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 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. Read the example again, and translate it 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 go through the same with the amended List example: function addPiToList(List $list): void // "I am a function that accepts any list, whose members can include Double" { $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" addPiToList($ln) // "You asked for a list that can contain Integers; 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"