|
|
|
|
|
by dexen
5495 days ago
|
|
Please elaborate on how it works? Perhaps I got this very wrong; never used an Either<> class. Would an attempt to access the value (if an error was indicated instead) cause error condition? Would it be similar in nature to an exception? |
|
Either is a tagged union (actually a sum type), you have a value OR an error, which are typed (haskell uses Left and Right as the constructors for Either, by convention Left holds an error and Right holds a value, because right is correct).
You can not just "cast" your Either, you have to type-check it with a case (or use monadic operators) to unwrap it, and with the right flag the compiler will ensure you're not missing cases. At compile time.
Either is basically Schrödinger's box (the computation resulted in both a value and an error), and the compiler checks that you're set for handling both a dead and a live cat, or it will not let you open the box.