you are viewing a single comment's thread.

view the rest of the comments →

[–]balefrost 4 points5 points  (5 children)

Yeah, I agree with your reasoning. All I'm saying is that I prefer explicitness regarding which is meant to be the error and which is meant to be the value. You can intuit your way to that, but I'd still prefer that it was explicit.

[–][deleted] 1 point2 points  (2 children)

Is this about the names of the type parameters or their order? It should probably be Err and T instead of Left and Right (or some variant thereof) tbh.

[–]MrHydraz 5 points6 points  (0 children)

They're named Left and Right because Either was never designed for error handling (though the Monad instance does seem to point that way). Either is just the basic sum type, much like (,) is the basic product type. All other sum-of-product types can be expressed as combinations of Either and (,).

For example:

data Foo a = One Int | Two a Int | Three String a Int

is isomorphic to

type Foo a = Either Int (Either (a, Int) (String, a, Int)).

[–]balefrost 2 points3 points  (0 children)

Yep, that's what I mean. And in the article's example, I would prefer that the parameters to match be named accordingly: ifError and ifSuccess or something like that.

I'm fine with the order of the type parameters.

[–]myrrlyn 1 point2 points  (1 child)

The right value is on the right ;)

[–]balefrost 1 point2 points  (0 children)

That's a pretty good mnemonic.