From 7e51363bf3434a2bf2edf12d1238922daea34cb6 Mon Sep 17 00:00:00 2001 From: Nikolaos Bezirgiannis Date: Mon, 20 Feb 2023 20:31:25 +0100 Subject: [PATCH] Add @since annotations for tryError,withError,handleError,mapError --- Control/Monad/Error/Class.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Control/Monad/Error/Class.hs b/Control/Monad/Error/Class.hs index b2465e7..93e3af3 100644 --- a/Control/Monad/Error/Class.hs +++ b/Control/Monad/Error/Class.hs @@ -206,6 +206,8 @@ instance catchError = Accum.liftCatch catchError -- | 'MonadError' analogue to the 'Control.Exception.try' function. +-- +-- @since 2.3 tryError :: MonadError e m => m a -> m (Either e a) tryError action = (Right <$> action) `catchError` (pure . Left) @@ -213,17 +215,23 @@ tryError action = (Right <$> action) `catchError` (pure . Left) -- Modify the value (but not the type) of an error. The type is -- fixed because of the functional dependency @m -> e@. If you need -- to change the type of @e@ use 'mapError' or 'modifyError'. +-- +-- @since 2.3 withError :: MonadError e m => (e -> e) -> m a -> m a withError f action = tryError action >>= either (throwError . f) pure -- | As 'handle' is flipped 'Control.Exception.catch', 'handleError' -- is flipped 'catchError'. +-- +-- @since 2.3 handleError :: MonadError e m => (e -> m a) -> m a -> m a handleError = flip catchError -- | 'MonadError' analogue of the 'mapExceptT' function. The -- computation is unwrapped, a function is applied to the @Either@, and -- the result is lifted into the second 'MonadError' instance. +-- +-- @since 2.3 mapError :: (MonadError e m, MonadError e' n) => (m (Either e a) -> n (Either e' b)) -> m a -> n b mapError f action = f (tryError action) >>= liftEither