Result monad
Nathan Linger
nlinger at janestreet.com
Tue Nov 27 20:34:35 GMT 2012
We've found that the pattern you mention works well in cases where you
want to recover from errors or handle distinct error cases in
different ways.
We've also found that often one merely wants to log errors and not
really handle them. For this use case, Error.t is a good choice for
the error type component of Result.t. In fact this is so common we
now use [type 'a Or_error.t = ('a, Error.t) Result.t] for many (most?)
Result-returning functions.
On Tue, Nov 27, 2012 at 3:27 PM, Malcolm Matalka <mmatalka at gmail.com> wrote:
> I've been playing with writing code that can fail in a lot of ways and
> using Result.Monad_infix to make it more readable. I've found that this
> only really works well if all of my functions that return a Result.t
> have polymorphic variants on the Error side. Is this the suggested best
> practice as well? I'm considering just mandating all my code that can
> return a Result.t does this.
>
> Thanks,
> /Malcolm
More information about the core
mailing list