Re: [RFC][Discussion] Objects can be declared falsifiable
| From: | Larry Garfield | Date: | Wed, 15 Jul 2020 17:14:36 +0000 |
| Subject: | Re: [RFC][Discussion] Objects can be declared falsifiable | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111028@lists.php.net to get a copy of this message | ||
On Wed, Jul 15, 2020, at 11:59 AM, Marco Pivetta wrote:
> Hey Larry,
> <http://ocramius.github.com/>
>
>
> On Wed, Jul 15, 2020 at 6:55 PM Larry Garfield <larry@garfieldtech.com>
> 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?
> > 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.
>
> Marco Pivetta
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.)
--Larry Garfield