7 ms·
> Errors are just a worse Either monad after allm they're much more pleasant to use than exceptions. How are errors in Go at all monadic? They just have a conv
by leshow 10y ago
> Errors are just a worse Either monad after allm they're much more pleasant to use than exceptions.
How are errors in Go at all monadic? They just have a convention where you return a tuple and manually check if something isn't nil. Either type will inhabit one variant or another, not both with one having a value of nil.
The 'monadic' part of Either (or Result in something like Rust, where try! is sort of like >>= if you squint) is the ability to chain Either types together and have the boilerplate abstracted, that feature is completely absent from Go. Errors in Go are neither the Either type nor monad, IMO.
- cube2222 10y agoAs I said, in practice they're a worse either monad. With which I meant -> they were inspired by them, but lack the monad part and having the value with the error in one object interchangeably. It's the same treating errors as values though.
- leshow 10y agoIt's really just a worse Either type, if anything, there's nothing monad about it. Although it's sort of hard to be close to an Either without being an algebraic data type. But I see what you're trying to say.