8 ms·
Exceptions can be modeled by a type like "Maybe" that simply also has the error information in it. So instead of a "Nothing", you have "Left err" with the "err"
by Peaker 14y ago
Exceptions can be modeled by a type like "Maybe" that simply also has the error information in it. So instead of a "Nothing", you have "Left err" with the "err" information in it.
The nice thing is that the same example using >>= above would work with Either's too, because it will just use the monad instance of Eithers, and you will get all the error information that way.
Exceptions, when represented this way, become a way that the error is handled by the caller rather than a different way to return. That way, the result of the function is well-described by its type.