Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117520 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23235 invoked from network); 11 Apr 2022 21:16:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Apr 2022 21:16:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EE74618053B for ; Mon, 11 Apr 2022 15:48:33 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 11 Apr 2022 15:48:33 -0700 (PDT) Received: by mail-lf1-f53.google.com with SMTP id u7so12089749lfs.8 for ; Mon, 11 Apr 2022 15:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=EciLQ/Du8qUbUsJhvZiLzC+Gl3oc/dTzTBn8Do8pcM8=; b=sFAsz7sOfrTalx3L4qi2b1Lv0r9FysZ5VPKrXxnBFWyhQnAZvaeKcwh/RBFN/ps+q3 8sVLx4nERS4EN0VKtXO6AeXMcFCmSA+K64WDOxj6UkwljRvEnPjB8EclWRc1pmpOqRHI LCPBjxLHuVbjSVj3v5GiaCV7eEZSuPLWxXBi0bcI4mZUC4IjqG8Qx2ATZxm1KEXGeprM SthKa65xhWnpVJyZyBClyMWFw3L/erKyGwvN3+NsC7FAAiLTw2gD436rHCSbnCRZXn15 8E7HNCLOICVKdFd9SpQ345src1JtIS7kF8lAqKjdJIAKRVLLr+IKWzsc+rV/e00FNcql wO4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=EciLQ/Du8qUbUsJhvZiLzC+Gl3oc/dTzTBn8Do8pcM8=; b=WVF767jTONM+c0mlZmqbVkHi/Y0CiApvdGODdm6cUvzE2Y7vV+BQLDikoCQXp1BGDu RkhiTOckEAtx3T9pj5RTXkmVWrvrYvclH7Ykm5jEa4pwJ9TIKbY3Ds/OC+sorMFKTEkf cL+k4lFad2ZpBubPS7YRozasMDv5SNq/GVeO366t8pM7KEhRaviqkjaPpFDppvcGebNR oV6aYpTIQAPDDMLeumQv67cyNB/DJOHoEmy9YHufpyNCqAflhQ8EVdPTtHm5J8lxou97 QMTYeHEs9W/MuFKOs6FxF/RCnq8CdnCTnMtwzoRr/rN7DEh7IkBorI+SVlS6DVW6BFlC 9mTA== X-Gm-Message-State: AOAM532ZUjh1fnkGIzrLcMmkThbsy85U3y5WqfXaEVrEWtDH37CpCKzS FBDcWbdrSfErR3z8dwutN8mK8IJ7IgjvvqXP4W5SYw== X-Google-Smtp-Source: ABdhPJySXcAeqaOU09VbwvhkL14R7eQ8DWJoA/XFJGGrViYWB048XlHqpDhFPpR7X7COkLeJdOzKhXFf5b8AacVlRqE= X-Received: by 2002:ac2:4202:0:b0:444:14bf:86dc with SMTP id y2-20020ac24202000000b0044414bf86dcmr23339672lfh.126.1649717311596; Mon, 11 Apr 2022 15:48:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 12 Apr 2022 00:48:20 +0200 Message-ID: To: Sara Golemon Cc: =?UTF-8?Q?Tim_D=C3=BCsterhus?= , "G. P. B." , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Add true as type From: andreas@dqxtech.net (Andreas Hennings) > sketch out a more complete picture for the type system. We can implement it in pieces and parts, but we should have a goal in mind for where we want to land. I think the type system in psalm is pretty cool. It does have fixed literal values, but also deeply structured array types. But: - I don't think we'll arrive there in one leap - I am not sure we _want_ to arrive there, ever. Perhaps it is just too much for native support, especially if we want repeated runtime checks. - Runtime checks on array types seem like a nightmare. - I am pretty confident that adding `true` won't close any doors fur future type systems, if we already have `false`. Alternatively we could look at compile-time type systems like in C++ (or Java?), where we don't have to waste time on runtime checks. The default implicit variable type could be "variant", but variables with a declared type would behave as in C++, with a faster and slimmer storage model. Of course any union type that allows values other than object or null would have to use the storage model of "variant". Sounds like a lot of work, but if we want to dream big, it is something to consider. (There might be better examples than C++, I only mention it because I spent some time with it long ago. Perhaps even Java?) -- Andreas On Mon, 11 Apr 2022 at 18:18, Sara Golemon wrote: > > On Mon, Apr 11, 2022 at 8:59 AM Tim D=C3=BCsterhus wro= te: > > For `true` the story is different, as this type is an entirely new type > > available to userland and by the same argument one could have literal > > strings or literal integers as distinct types as well. I wouldn't objec= t > > to that per se (and there's precedent in TypeScript), but there could b= e > > a clearer plan for the type system as a whole, instead of adding types > > piecemeal. > > > > ^This. The bit about making a plan, I mean. A slow erosion of what it > means to be a type might be the easier pill to swallow, but it results in > more chaos overall in the type system. I'd like to see someone (literall= y > anyone) take the time to sketch out a more complete picture for the type > system. We can implement it in pieces and parts, but we should have a go= al > in mind for where we want to land. > > Using this RFC as an example, it naturally leads into the question of val= ue > types (which is what `true` really is, a bool with a value of true), so w= hy > can't we say this method must return the number 42 or a string containing > 'pamplemousse' ? A roadmap would help us understand what those kinds of > value types (in an unbounded type like string or a large bounded type lik= e > int) compared to the tight bounded type of bool. > > And yes. Generics. We can't talk about the type system without the > subject of generics being extremely relevant. Ignoring them because it's > complicated is just kicking the can down the road. > > All that having been said, sure. I don't mind adding true for completenes= s, > because it's fairly obvious and the scope of bool is fairly small, but I > would really encourage anyone to step up and plan out a wider reaching go= al > for the type system. > > -Sara