Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101440 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16240 invoked from network); 29 Dec 2017 15:37:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Dec 2017 15:37:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.53 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.53 mail-it0-f53.google.com Received: from [209.85.214.53] ([209.85.214.53:45601] helo=mail-it0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 78/1A-47595-131664A5 for ; Fri, 29 Dec 2017 10:37:23 -0500 Received: by mail-it0-f53.google.com with SMTP id z6so31353044iti.4 for ; Fri, 29 Dec 2017 07:37:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=+jtLIHYSYheN3iN2sHFZliIRS6ArdYPFPO6A68ZEfEk=; b=QvFqnJtefU0Yr0bEcXNIa+k49cOyyj4/z+ukvRUq9pr7HtY8RNUbS0WFJlzUXGfyom ZJ0ZP/ubFeLUf428XNqnGW7SrXDPBAIfOpTEFpcRWPxSjrAO7wbmo3ufBFga0i0uhiL0 aSxOO94zdg5p2msNoBJDDQsmqahQckXDbnKorsPmDQ2LLKukzcQQE0RWTaBEZX/N9d/I YvbwOzLSMWT/ElfokS3pwP3+1jVTu4+NLVgW8QxgDTIY3rlR0edW0iP1Tt+mvb2SBqGK gola9+55neNyZA2oO4GC1B47QdghI/ymUIDwXblEP+8qYuHo58H3N1CIfq4kRc0RvmWt vy9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=+jtLIHYSYheN3iN2sHFZliIRS6ArdYPFPO6A68ZEfEk=; b=ARNHiViu1v1tM6b/b8s/AoUwzhx+JNHHabSR9sPLQPPrjgJV5amOc0GPOxDqV4LRoV aD5NZG3Jv1OlkFxrXktBJiBh2SBIlfIi+iWnrdfpo7lNVqO9JCWff5k17v2ZYbaO2aho ll86X5SIbEg5aBurQBCqWYmF8qvNocOW8N7mGMF9NW6zgqkeZD20324z9jw5+BVXw0nB c809OA232TQEAHIN7Vh7rW82vFI+tuf9NDBMZ9RU08AkiTnnWGvLUKc+eeRxC21Y949t 4r0B5bTkCdQUowWU5TeVy4bag38dLN+RKmaDZ4kSCBn7i6pi4GCIHvCjQvggvMGcnQiO 0jgQ== X-Gm-Message-State: AKGB3mKEFdrZ1ivMqJSYRHzTS/+AT0yS4V90QcCgn4vHXXA2Y3pxGtBc 2c1dMAzKpyVqgwFG931oB97/SQJoGv2wrvFK8II= X-Google-Smtp-Source: ACJfBosH+8UqqxM9qF227s1gYDUskP63H81RSOjNKjnBUYoo2eUFVVHqBKbrs4zUuP/L6vPFC+b3MmKH5SFuOuJiSnM= X-Received: by 10.36.81.82 with SMTP id s79mr47012358ita.144.1514561837435; Fri, 29 Dec 2017 07:37:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.53.216 with HTTP; Fri, 29 Dec 2017 07:37:16 -0800 (PST) In-Reply-To: References: <72392123-d37b-26df-6886-218f48205f8a@fleshgrinder.com> <58A5ABDF-AA25-46D4-83E7-4DE72E3DFF5E@gmail.com> <757270790.33iDQ9MZ2V@vulcan> Date: Fri, 29 Dec 2017 16:37:16 +0100 Message-ID: To: PHP internals Cc: Larry Garfield Content-Type: multipart/alternative; boundary="001a113faf504f905205617c686a" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Scalar Pseudo-type From: nikita.ppv@gmail.com (Nikita Popov) --001a113faf504f905205617c686a Content-Type: text/plain; charset="UTF-8" On Fri, Dec 29, 2017 at 1:08 PM, Fleshgrinder wrote: > 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`). > int|float is the natural type of numeric operations in PHP. Integers automatically overflow into floating point numbers, so signatures using int in conjunction with numeric operations are somewhat problematic. Having an explicit number type also goes well with an explicit number cast. PHP internally has a notion of a number cast (which is the basis for arithmetic operations), but currently does not expose it. As such, number casts currently have to be simulated using workarounds like +$x. Regarding the union type RFCs, from what I remember, one of my personal issues with it were the complex rules involving scalar type unions in weak typing mode. It's non-trivial to decide what a value should be casted to if it does not have the correct type. It's sort of clear what "1.5" passed to an int|float union becomes, but it's not intuitively obvious what should happen if you pass "foo" to a bool|int union, etc. Regards, Nikita --001a113faf504f905205617c686a--