Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92348 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83062 invoked from network); 15 Apr 2016 18:04:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Apr 2016 18:04:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.26 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.26 out2-smtp.messagingengine.com Received: from [66.111.4.26] ([66.111.4.26:60347] helo=out2-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 98/39-29891-82D21175 for ; Fri, 15 Apr 2016 14:04:24 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id BEFEA20874 for ; Fri, 15 Apr 2016 14:04:21 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Fri, 15 Apr 2016 14:04:21 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=Na4DdogS/b9fdD4 PwoSA8jcjl/4=; b=abk8t7FQE4tNL1f/DY0QckZgMhHcIbOZ3L39MgePeZnJbNE pEJTP25aWTLvA7iqaKQND6VqIDCplP6h4oke+NMxgqHvX6Myw8nbrhmwcls+eS5o G/x3yP0J2pLMUX2waTPwoHMQki/Kfglr4HoC8BeF9yPZ90BCUKQK61lKuzLs= X-Sasl-enc: 6VYrmHYvmdGvYVmL9CDWd7/vQOzfPyyvwStXWJfqpQn2 1460743461 Received: from Crells-MacBook-Pro.local (unknown [63.250.249.138]) by mail.messagingengine.com (Postfix) with ESMTPA id 88A5DC0001A for ; Fri, 15 Apr 2016 14:04:21 -0400 (EDT) To: internals@lists.php.net References: <570E99AC.3090804@fleshgrinder.com> <570EA5EB.8090501@fleshgrinder.com> <570EAB0D.6080706@gmail.com> <570EB67E.8010908@garfieldtech.com> <5B147E88-CC0A-4CBC-A49D-C7FE3BF557C0@zend.com> <6F.C3.12455.94C5F075@pb1.pair.com> <20160414094440.GF19347@phcomp.co.uk> <570FD94F.90703@fleshgrinder.com> <570FE8A9.4020809@gmail.com> <20.53.29891.17401175@pb1.pair.com> Message-ID: <57112D25.4000605@garfieldtech.com> Date: Fri, 15 Apr 2016 13:04:21 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Improving PHP's type system From: larry@garfieldtech.com (Larry Garfield) On 4/15/16 12:16 PM, Lin Yo-An wrote: > Andrea Faulds 於 2016年4月15日 星期五寫道: >> >> This is something that particularly concerns me about union types, in that >> they reduce type safety. If you have a union type of Foo|Bar for some >> variable, then the set of methods you can call on that variable is actually >> the intersection, not the union, of the set of methods you can call on Foo >> and Bar. Which, unless those two classes share some interface, is probably >> an empty set. So there's nothing you can actually do safely with it without >> doing checks within the body of the function, and if you're doing that, >> then why do we have a type declaration? It's only barely more useful than >> omitting a type declaration at all; type declarations are supposed to >> prevent you needing to check. On the other hand, if the two classes share >> some methods, then either there's an interface you can already use here, or >> you can create one. Either way, you don't need a union type. > +1 I agree. Language like Golang use interface to intersect the method > calls, I think that's better. Go's interfaces are implicit rather than explicit. That's what makes micro-interfaces like that (which are often single-method) feasible. Anthony Ferrara proposed "weak interfaces" a few years ago but it was rejected (or didn't make it to a vote; I don't recall which). Either way, Foo|Bar is not the main use case for union types. See my earlier email. -- --Larry Garfield