Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112551 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28793 invoked from network); 18 Dec 2020 20:08:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Dec 2020 20:08:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F272D1804F3 for ; Fri, 18 Dec 2020 11:40:41 -0800 (PST) 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,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 ; Fri, 18 Dec 2020 11:40:41 -0800 (PST) Received: by mail-lf1-f48.google.com with SMTP id 23so8252964lfg.10 for ; Fri, 18 Dec 2020 11:40:41 -0800 (PST) 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=8MBPJkLkYZLN5SPXWr2/BhvUQevdmmZmXbwbHK2sSrE=; b=d8A7vJiwB9s+Qt5/mJ3qXKs1aSSTSY6p4MNEZ4UzUtALszKix6Ief0IBRo6dIVqcZ6 jKEIABrrpqJnJ2Kq+Y1K9q4hTWMO83XJ74Up3hM8bpwkM8H1j9edRkFCyLWW5qkjp3z0 nuK4YJfkS0Nm8JPCB3Qf5Nclve7xt5Xb8CwPYKdAmsGhTA1l4JbQP+AWV8FGqTsrPKO1 G16705k7LwYA52H5wMOXdX4K6eJOiEwQaoI5cpAwAhRPB+fHXoAynSFBecOICTIMUZAw 9Qp9HXDXHV1f0S5bgD1vDcRU1Y4Xj/rOIAv4baNRc6M41BNQEqqG1g8eLima+qJ9wgM7 JbCg== 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=8MBPJkLkYZLN5SPXWr2/BhvUQevdmmZmXbwbHK2sSrE=; b=hXSp51l8chUQNrVLWVRp46EgKGu1zq5+f2UurQ9nWHMo7mB3hIoP1PhhsBUWMbvRfG LIr1KUPhyGCwZilwxAk/NKe/k7rR3RzccjnNkRIPOV+rd4/HJuH5+i6zFjh+Q1111VbQ 3U3X/1lsaiea9JI4m1x8/8iobbwPgNDoafDrq9vrCxHuGJKTm8ClzseICIaq4vdgcnt0 YRmN05dNgaNfVDVlO5M7TDI5ygqM+yD5AkyHggGAJOiY1wy9DJWX/oCsgeMT6fPN9hKn GQpGDLPNezZOQ8UPySXhp0yaHFZH/gyyQZ6/HnE9PZWofITLgBFSPnC4SjNVlub3cc7k 4ebA== X-Gm-Message-State: AOAM532mf3+0YgPN9NPHudm+rSGtzouqdUYk+JpgAbgL8AMxQPBSIAqa 6To3/0eCivFGmpzPl69Ud5oxObltZ3DZXAy4JZWB2pHUyOw= X-Google-Smtp-Source: ABdhPJzcG9B+cwOcbT0XtQkg/f/I9ZiHJmRJTcM5XGaVKhsQTy6KBZiBgaYEBvxUb26e6dv/AL3AgEJf9cbaPvYrGQ0= X-Received: by 2002:ac2:5970:: with SMTP id h16mr2271424lfp.338.1608320437538; Fri, 18 Dec 2020 11:40:37 -0800 (PST) MIME-Version: 1.0 References: <490a62fb-f6f4-4d7b-b46d-571abfa28618@www.fastmail.com> In-Reply-To: <490a62fb-f6f4-4d7b-b46d-571abfa28618@www.fastmail.com> Date: Fri, 18 Dec 2020 20:40:24 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000005d539a05b6c24894" Subject: Re: [PHP-DEV] [RFC] Short-match From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) --0000000000005d539a05b6c24894 Content-Type: text/plain; charset="UTF-8" What about matching on a variable's type? ``` match { $var: string => "is a string" $var: array => "something else" } ``` This could be used with flow-sensitive typing, e.g. assume the type of $var being string in the string block. Psalm works like this for if-statements. Also consider the case with generics. Compare with generalised algebraic data types in FP (GADT). Olle On Thu, 17 Dec 2020, 22:01 Larry Garfield, wrote: > On Thu, Dec 17, 2020, at 10:23 AM, Sara Golemon wrote: > > On Wed, Dec 16, 2020 at 6:50 PM someniatko wrote: > > > > > > `match` is an expression, where as if-else construction is not. This > > > allows for combining it with a potential future feature of single line > > > functions and methods. For example (hypothetical syntax is used): > > > > > > ``` > > > $getNumber = fn(int $number) => match { > > > $number < 0 => NumberKind::NEGATIVE, > > > $number == 0 => NumberKind::ZERO, > > > $number > 0 => NumberKind::POSITIVE, > > > }; > > > ``` > > > > > > > That does read attractively, yes. This is the example that should have > > been offered first as it shows the expression nature shining. > > > > To contrast that with what would be possible now in an expressive > > functional form: > > > > $getNumber = fn(int $number) => [ > > -1 => NumberKind::NEGATIVE, > > 0 => NumberKind::ZERO, > > 1 => NumberKind::POSITIVE, > > ][$number <=> 0]; > > > > The match form *certainly* reads more naturally than the spaceship > indexing > > form even though both take up equal space. > > > > -Sara > > It looks like the quoted part from someniatko changed from a named > function to an anon function? Not sure what happened there. > > I've included both a named and lambda version of his example in the RFC, > however, and linked to the short-functions RFC as that would allow the form > he originally listed. They complement each other nicely. > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --0000000000005d539a05b6c24894--