Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109790 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24997 invoked from network); 22 Apr 2020 22:13:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Apr 2020 22:13:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BFAC91804B4 for ; Wed, 22 Apr 2020 13:45:11 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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-ua1-f52.google.com (mail-ua1-f52.google.com [209.85.222.52]) (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 ; Wed, 22 Apr 2020 13:45:11 -0700 (PDT) Received: by mail-ua1-f52.google.com with SMTP id i5so3390214uaq.1 for ; Wed, 22 Apr 2020 13:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=o+MQeBiBXIN84ZuZsMVJpnTJMI0r4zskrI9hZhtUSGM=; b=S4eLlDGVfsTSQ1xX0lzCOeFLmE6h9jbPznK1xFsGT/jZiZwG0+dT/EqUR0e+nw9JTX vFovDwE9CZqk5yZtBMWYFqSHa0rQpwELwy3CyaOXCc4Xl2f15c1fE3omNAx2AnSomw6U Mvs8vlBBpgcGJ3wnC56UdvgwhhruRZnFnPMh1Aiwq/2sm2IQTAG6zP9cU9oTANYOrPAA /NOL52kCjAgz2RNuoSFcVHHz95Gs3+vfaoHN1nfNoOxJIQJvydsz002/eK5jVcZHrChr JAYSbAJT4eNX0h4vYfIVqnkthIEoRz6BYAAm6AjwDYY0ovICJ3L54bY7eG7WpbZpZx09 Keng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=o+MQeBiBXIN84ZuZsMVJpnTJMI0r4zskrI9hZhtUSGM=; b=OF6XlvnwTx9eumiG0moK5KCefEb13vjeske+DMd9Z+qC0fJZuD/vg/Binieiub4kpO wCLPaCNA5W90K+EtVEwGjQlV6Qwxy2H2GU6Lij5tJ4fkqE7L72Se5i1G+g4pcQWmKQzY /g7IozJQ/OAyzO4EBUTg9rzTVdK4iv/G6fYES6Z/8WKYSURQ8b2abJWK4ZNAhDNAnaG8 pZNTxlTojU6qm9dCkxEoYeutozyPWsTSF+k2X0VRXFjG5hEfeoD8wTAi6p3FQPb2Xh+6 botZd/TM1zz5DJVCuIIGupFQQATdjl8mXnZ1p7siWWj9d8e2yNTE8exH/yB3covRdURN M05w== X-Gm-Message-State: AGi0PuYA9MXcvbETTNIbZXgqxPW52QUvV4KFIX1PsZvzQquJ94IG0v+s plSqV96xahlofgu6ZNiDTu6xf4s5FX+jj9WE5sE= X-Google-Smtp-Source: APiQypLSTBHgVU7Tkwpvcy25q/YcuX6Ey2Snl0EBqOzvswvOjORq4aNMeEw/yCDzNsnMHakflI5Nt2Ooy/uvfjmCbEg= X-Received: by 2002:ab0:3762:: with SMTP id o2mr339925uat.119.1587588309502; Wed, 22 Apr 2020 13:45:09 -0700 (PDT) MIME-Version: 1.0 References: <4c1cd016-1e41-4ebc-afc4-d8d3cd1c319b@www.fastmail.com> <31441489-11c6-4d99-9c53-6ac0e877f268@www.fastmail.com> In-Reply-To: <31441489-11c6-4d99-9c53-6ac0e877f268@www.fastmail.com> Date: Wed, 22 Apr 2020 16:44:58 -0400 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000003cd0c405a3e7358a" Subject: Re: [PHP-DEV] Any interest in a list type? From: matthewmatthew@gmail.com (Matthew Brown) --0000000000003cd0c405a3e7358a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > map/filter/reduce need to be recast to work on any iterable, which would then include lists > Lists would only make sense if we're also rethinking how collections work generally I disagree =E2=80=93 I think the most successful PHP language additions hav= e been those that allow PHP developers to improve their code without having to think too hard =E2=80=93 for example, property, return and param types can = be added to existing code without changing its behaviour at runtime, as long as the added types align with actual behaviour. If list types work in a wholly different fashion to arrays, they won't be a drop-in-replacement, they won't feel familiar to the average PHP developer, and I imagine few people would update existing code to use them, because it'd be too risky. On Wed, 22 Apr 2020 at 15:01, Larry Garfield wrote= : > On Wed, Apr 22, 2020, at 1:49 PM, Matthew Brown wrote: > > > Is it an effective subtype of array? > > > > I was thinking it should be (with the auto-conversion mentioned above), > but > > I can see a compelling case to not have the auto-conversion when > > manipulating =E2=80=93 while it would bloat the stdlib a little (we'd n= eed a > whole > > bunch of list_* functions) the separation would simplify things a lot > (e.g. > > list_filter would return a list with sequential keys, whereas > array_filter > > returns an array with possibly non-sequential keys) > > > > And then you could cast between the two like "(list) $some_array" (whic= h > > would preserve order but remove keys) and "(array) $some_list" as > > necessary. There could even be some automatic list <-> array casting wh= en > > calling functions not in strict_types mode. > > > > > Should they pass like arrays or like objects > > > > Definitely like arrays =E2=80=93 I want them to be a drop-in-replacemen= t for > people > > who currently use arrays in places lists are more appropriate. > > > > > Should they be mutable or immutable > > > > Definitely mutable, like arrays are > > That has a long list of possible issues with it relating to spooky action > at a distance, depending on the passing semantics. In some languages lis= ts > are immutable, and with PHP's copy-on-write it may make more sense to jus= t > go immutable. > > > > Are they iterable > > > > Yes, the keys are sequential integers > > > > > Does it make sense to add them without type enforcement via generics > > > > Absolutely =E2=80=93 this shouldn't be tied to generics landing (which = I'd > imagine > > is a PHP 9 feature at this point, whereas this could be a PHP 8.x > feature). > > > > > can they be mapped/filtered/reduced > > > > Absolutely =E2=80=93 I think we'd have list_map, list_filter, list_redu= ce > functions > > to provide that functionality. > > Why duplicate all of them? Rather, map/filter/reduce need to be recast t= o > work on any iterable, which would then include lists. Or, if lists are a= n > object they would be methods on the object. > > Hence my point. Lists would only make sense if we're also rethinking how > collections work generally, for which we're already overdue. Just tossin= g > them in as yet-another-different-thing would make the situation worse, no= t > better. > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --0000000000003cd0c405a3e7358a--