Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111029 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 41279 invoked from network); 15 Jul 2020 18:29:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Jul 2020 18:29:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 444D0180559 for ; Wed, 15 Jul 2020 10:22:16 -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,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-il1-f193.google.com (mail-il1-f193.google.com [209.85.166.193]) (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, 15 Jul 2020 10:22:15 -0700 (PDT) Received: by mail-il1-f193.google.com with SMTP id o3so2640977ilo.12 for ; Wed, 15 Jul 2020 10:22:15 -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=oZbAi1e/WcagOeCB1c+sF7j72bbxvm5eoqXjyd3e8Zg=; b=nSWLaFiLyt6FOI8sOHGjN8HZH9pt01js6aoLRfbyzWVKGzhmReFAhtWFFtvJtlE6fK NttBmqBftnIOYXVkKNS1x+8tsCJRxm9qqb26nBp+Lgf0R48CvE9NCeENx8aMOOZnYTPV RP4Uw6NaEVnjnoecq7YFAwkHBUvz4ABjqNtyJNByjc5xSVVJXd9m7U7JB4tD7RoXsPUu luEcx30JdbxuEuHW16zy1kNIuoJlAfIErECHuGhfIZazdTvFJPt+A24xSS233eqwxlEr nW6qI9kVqNSX/vlYdD3sPNhNjy7XO2CS1XRuTuNjosZlDJoP+AyZOoM2FVxgubIM6bPZ sKXg== 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=oZbAi1e/WcagOeCB1c+sF7j72bbxvm5eoqXjyd3e8Zg=; b=i5HOEw1plEmaO1tqBPkvbEjpkyS4+EAzM/0DlEU9FnjUK8JzRa+faERxYZ5Q5sOO+5 BmM+xCJqBfV5Jv6ml4YNxRio5SOIdsW6VOumzLXxkRV80WhgLN5EEQ1/n61KLynUVE/Y f1myPk5KGBPVkCSyK/KCzWkJ567F+Vk4rvknhte9/H72w65rghTO1C5z4GLxS25UF5WJ 2fn3dkGpPOenjHCwsCAwRNq0Ui5EbIake+C3XHz2ybY+uOWaoZVbOzPJ2VT0Bvkl3jUl LjGy7v82kUCC4uNy2sgjQVvUSkrAfFh4m97+k+UOmyJZ2ubT+W+THxt0zgNDs7rzFEUH QoLw== X-Gm-Message-State: AOAM5306/cWkr2AFxSIPaDU/WMUZ3lAebLyWcvjUXCL3FTPtCLKdU48o XpKWJaa2lAH91eGMURX3t2THGb0XYai0HAIMQS4= X-Google-Smtp-Source: ABdhPJyGe/oZZkkGGOQxAr437eELTLfs2KfMlbOT9fp+Oj8iy9B1q0KlsMjiPNL9+gaQU8iIJGEbXNKm4nzGYuSeMRc= X-Received: by 2002:a92:cc4d:: with SMTP id t13mr485741ilq.283.1594833732795; Wed, 15 Jul 2020 10:22:12 -0700 (PDT) MIME-Version: 1.0 References: <21C5073D-3F39-49DA-8686-E027AE780793@joshbruce.dev> <2d0fea79-0729-4cce-8b3a-be834614f242@www.fastmail.com> <1a34b907-4766-4c13-9da3-34a3df527679@www.fastmail.com> In-Reply-To: <1a34b907-4766-4c13-9da3-34a3df527679@www.fastmail.com> Date: Wed, 15 Jul 2020 19:22:01 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000001e817f05aa7e2ac8" Subject: Re: [PHP-DEV] [RFC][Discussion] Objects can be declared falsifiable From: ocramius@gmail.com (Marco Pivetta) --0000000000001e817f05aa7e2ac8 Content-Type: text/plain; charset="UTF-8" Hey Larry, On Wed, Jul 15, 2020 at 7:15 PM Larry Garfield wrote: > On Wed, Jul 15, 2020, at 11:59 AM, Marco Pivetta wrote: > > Hey Larry, > > > > > > > > On Wed, Jul 15, 2020 at 6:55 PM Larry Garfield > > wrote: > > > > > I disagree entirely. The value of a Maybe over just null is > > > > > > 1) You can bind to it even if the result is empty; the "if is null" > check > > > gets abstracted away from the main code. > > > > > > > That's correct: that's how the `Maybe` monad works too. > > That... is what I'm describing? A Maybe Monad? > Sorry, my wording wasn't right. `>>=` implemented for `?T` does the exact same thing as `>>=` implemented via `Maybe T`: same abstraction, different implementation (`instance Monad ?T` vs `instance Monad Maybe`). Therefore, if we had monadic syntax, you could write the following code: ```hs do value <- someCall someInput someOperation <- someOtherCall value return value ``` The above would work with both `?T` and `Maybe T`, luckily. > > > 2) You are forced to unwrap/extract the value if you're not just > binding, > > > which makes it less likely you'll forget to check if it's null > > > > > > No need to unwrap: that's what `>>=` does for you. > > > > Assuming you use psalm or phpstan, a program that doesn't use `>>=`, or > > forgets to check for `null` on `?T` does not type-check anyway, and can > be > > rejected before even writing any runtime tests: that's sound. > > My Haskell experience is zilch, but since PHP lacks a dedicated bind > operator that also magically unwraps, that doesn't seem relevant. (Mind > you, I'd be all for a dedicated bind operator that also auto-unwraps! But > that's not on the radar at the moment.) > No need for magic operators: just because `>>=` is written with an infix operator in Haskell doesn't make it magic. In fact, Marco Perone released a nice PHP type-safe FP library around functional PHP abstractions today, and `>>=` is implemented as `bind()` there: * https://github.com/marcosh/lamphpda/blob/ebde827e78f0d5889da041fecfea353817890e35/src/Maybe.php#L175 * https://github.com/marcosh/lamphpda/blob/ebde827e78f0d5889da041fecfea353817890e35/src/Typeclass/Monad.php#L22 You can use that today: it already brings some value to the table, without any need for language-level additions (besides generics) :) Greets, Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --0000000000001e817f05aa7e2ac8--