• Petr Pudlak's avatar
    Add functions for manipulating errors in Result(T) · 27a5367a
    Petr Pudlak authored
    There is often need to manipulate these errors, for example to convert a String
    from Result into an exception. These functions make this easier.
    Function 'toErrorStr' lifts 'Result' to any 'MonadError'. This is useful
    for converting 'Result' into 'ResultT' or any other similar monad stack.
    Functions 'catchErrorT' and 'handleErrorT' catch errors just as 'catchError'
    does, but also allow to change the error type.
    Functions `withError` and `withErrorT` allow to modify an error within
    GenericResult or ResultT. This is convenient when combining functions
    with different error types, for example to convert between strings and
    Furthemore, 'failError' generalize 'Bad'. It can be used anywhere 'Bad' is, and
    in any 'MonadError' instance.
    Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
    Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
    Cherry-pick of 565821d1
    Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
    Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
BasicTypes.hs 11.9 KB