Skip to content

Commit 6be8cb5

Browse files
authored
Merge pull request #143 from bezirg/master
Add @SInCE annotations for tryError,withError,handleError,mapError
2 parents 6f20acc + 7e51363 commit 6be8cb5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Control/Monad/Error/Class.hs

+8
Original file line numberDiff line numberDiff line change
@@ -206,24 +206,32 @@ instance
206206
catchError = Accum.liftCatch catchError
207207

208208
-- | 'MonadError' analogue to the 'Control.Exception.try' function.
209+
--
210+
-- @since 2.3
209211
tryError :: MonadError e m => m a -> m (Either e a)
210212
tryError action = (Right <$> action) `catchError` (pure . Left)
211213

212214
-- | 'MonadError' analogue to the 'withExceptT' function.
213215
-- Modify the value (but not the type) of an error. The type is
214216
-- fixed because of the functional dependency @m -> e@. If you need
215217
-- to change the type of @e@ use 'mapError' or 'modifyError'.
218+
--
219+
-- @since 2.3
216220
withError :: MonadError e m => (e -> e) -> m a -> m a
217221
withError f action = tryError action >>= either (throwError . f) pure
218222

219223
-- | As 'handle' is flipped 'Control.Exception.catch', 'handleError'
220224
-- is flipped 'catchError'.
225+
--
226+
-- @since 2.3
221227
handleError :: MonadError e m => (e -> m a) -> m a -> m a
222228
handleError = flip catchError
223229

224230
-- | 'MonadError' analogue of the 'mapExceptT' function. The
225231
-- computation is unwrapped, a function is applied to the @Either@, and
226232
-- the result is lifted into the second 'MonadError' instance.
233+
--
234+
-- @since 2.3
227235
mapError :: (MonadError e m, MonadError e' n) => (m (Either e a) -> n (Either e' b)) -> m a -> n b
228236
mapError f action = f (tryError action) >>= liftEither
229237

0 commit comments

Comments
 (0)