<http://ocramius.github.com/>Hey Larry,
On Wed, Jul 15, 2020 at 7:15 PM Larry Garfield <la...@garfieldtech.com> wrote: > 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 <la...@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? > 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/