From 1315882cf56e2e15600633d04af86e21dfc0cda1 Mon Sep 17 00:00:00 2001 From: Luke Worth Date: Mon, 16 Dec 2024 16:45:17 +1100 Subject: [PATCH] feat: hoistError' and hoistErrorM' --- hoist-error.cabal | 2 +- src/Control/Monad/Error/Hoist.hs | 16 ++++++++++++++++ src/Control/Monad/Fail/Hoist.hs | 10 ++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/hoist-error.cabal b/hoist-error.cabal index 172073f..2de65a9 100644 --- a/hoist-error.cabal +++ b/hoist-error.cabal @@ -1,5 +1,5 @@ name: hoist-error -version: 0.3.0.0 +version: 0.3.1.0 synopsis: Some convenience facilities for hoisting errors into a monad description: Provides a typeclass and useful combinators for hoisting errors into a monad. license: MIT diff --git a/src/Control/Monad/Error/Hoist.hs b/src/Control/Monad/Error/Hoist.hs index 7d462ef..195ead8 100644 --- a/src/Control/Monad/Error/Hoist.hs +++ b/src/Control/Monad/Error/Hoist.hs @@ -36,7 +36,9 @@ module Control.Monad.Error.Hoist ( hoistError + , hoistError' , hoistErrorM + , hoistErrorM' -- ** Operators -- $mnemonics , (<%?>) @@ -70,6 +72,13 @@ hoistError -> m a hoistError f = foldError (throwError . f) pure +-- | @hoistError' = hoistError id@ +hoistError' + :: (PluckError e t m, MonadError e m) + => t a + -> m a +hoistError' = hoistError id + -- | A version of 'hoistError' that operates on values already in the monad. -- -- @ @@ -84,6 +93,13 @@ hoistErrorM -> m a hoistErrorM e m = m >>= hoistError e +-- | @hoistErrorM' = hoistErrorM id@ +hoistErrorM' + :: (PluckError e t m, MonadError e m) + => m (t a) + -> m a +hoistErrorM' = hoistErrorM id + -- $mnemonics -- -- The operators in this package are named according to a scheme: diff --git a/src/Control/Monad/Fail/Hoist.hs b/src/Control/Monad/Fail/Hoist.hs index b566df6..d5dcaeb 100644 --- a/src/Control/Monad/Fail/Hoist.hs +++ b/src/Control/Monad/Fail/Hoist.hs @@ -41,7 +41,7 @@ hoistFail -> m a hoistFail f = foldError (fail . f) pure --- | Hoist computations whose error type is already 'String'. +-- | @hoistFail' = hoistFail id@ hoistFail' :: (PluckError String t m, MonadFail m) => t a -> m a hoistFail' = hoistFail id @@ -59,13 +59,7 @@ hoistFailM -> m a hoistFailM f m = m >>= hoistFail f --- | A version of 'hoistFail'' that operates on values already in the monad. --- --- @ --- 'hoistFailM'' :: 'MonadFail' m => m ('Maybe' a) -> m a --- 'hoistFailM'' :: 'MonadFail' m => m ('Either' a b) -> m b --- 'hoistFailM'' :: 'MonadFail' m => 'ExceptT' a m b -> 'ExceptT' a m b --- @ +-- | @hoistFailM' = hoistFailM id@ hoistFailM' :: (PluckError String t m, MonadFail m) => m (t a)