Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101433 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98151 invoked from network); 29 Dec 2017 12:08:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Dec 2017 12:08:32 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.83 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.83 mx102.easyname.com Received: from [77.244.243.83] ([77.244.243.83:47335] helo=mx102.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/B7-47595-B30364A5 for ; Fri, 29 Dec 2017 07:08:30 -0500 Received: from cable-81-173-133-76.netcologne.de ([81.173.133.76] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1eUtSZ-0006w1-7y; Fri, 29 Dec 2017 12:08:24 +0000 Reply-To: internals@lists.php.net To: Larry Garfield , internals@lists.php.net References: <72392123-d37b-26df-6886-218f48205f8a@fleshgrinder.com> <58A5ABDF-AA25-46D4-83E7-4DE72E3DFF5E@gmail.com> <757270790.33iDQ9MZ2V@vulcan> Message-ID: Date: Fri, 29 Dec 2017 13:08:16 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <757270790.33iDQ9MZ2V@vulcan> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-DNSBL-PBLSPAMHAUS: YES Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Scalar Pseudo-type From: php@fleshgrinder.com (Fleshgrinder) On 12/29/2017 12:21 AM, Larry Garfield wrote: > On Wednesday, December 27, 2017 3:50:54 AM CST Rowan Collins wrote: >> On 26 December 2017 18:35:29 GMT+00:00, "lists@rhsoft.net" > wrote: >>> Am 26.12.2017 um 19:18 schrieb Larry Garfield: >>>> If I may, I think the argument has always been that >>>> >>>> 1) Foo & Bar makes total sense >>>> 2) int|float makes total sense >>>> 3) int & string is illogical so wouldn't matter anyway >>> >>> not true >>> >>> function x(int|string $x) >>> { >>> >>> $x = (int)$x; >>> >>> } >> >> I think there's a misunderstanding here. Some previous proposals for "union >> types" also included "intersection types", so that you could assert >> "parameter must implement both of these interfaces". So 'Foo|Bar $x' would >> mean '$x instanceof Foo || $x instanceof Bar' and 'Foo&Bar $x' would mean >> '$x instanceof Foo && $x instanceof Bar'. >> >> I presume that's what Larry means by "int & string is illogical", because it >> would translate to "is_int($x) && is_string($x)", which is false for all >> values of $x. This is different from "int | string", which, as you say, >> might have valid uses. >> >> Regards, > > Correct. Union types I've always seen presented as offering both union and > intersection. There are cases where union is great, and where it's kinda > silly. There are cases where intersect is great, and where it's kinda silly. > > Most of the anti- arguments I've seen for "union types" have fixated on "int && > string is meaningless, and Foo || Bar is bad design, so union types are bad!" > Entirely ignoring the flip side, which is int || string (valid use cases) and > Foo && Bar (many many valid use cases). > > --Larry Garfield > What is the use case for `int|float`? I mean, if f is able to process a `float` than f is able to process an `int` and since `int` is already automatically changed to a `float`, well, you're done. The only situation (I can think of) where this might make a difference is while formatting them. However, in those cases one usually wants to accept many more types (or better yet, let the type format itself). I think that the union RFC was missing proper rules for disjunction (and conjunction if intersection were to be included) as well as information on disjointness. The latter would be important for exhaustive switches that are enforced by the runtime (we'd probably need new keywords here, e.g. `match` + `is`). -- Richard "Fleshgrinder" Fussenegger