hoist-error 0.2.0.1 → 0.2.1.0
raw patch · 3 files changed
+71/−51 lines, 3 filesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Control.Monad.Error.Hoist: hoistErrorM :: HoistError m t e e' => (e -> e') -> m (t a) -> m a
- Control.Monad.Error.Hoist: (<!?>) :: HoistError m t e e' => m (t α) -> e' -> m α
+ Control.Monad.Error.Hoist: (<!?>) :: HoistError m t e e' => m (t a) -> e' -> m a
- Control.Monad.Error.Hoist: (<%!?>) :: HoistError m t e e' => m (t α) -> (e -> e') -> m α
+ Control.Monad.Error.Hoist: (<%!?>) :: HoistError m t e e' => m (t a) -> (e -> e') -> m a
- Control.Monad.Error.Hoist: (<%?>) :: HoistError m t e e' => t α -> (e -> e') -> m α
+ Control.Monad.Error.Hoist: (<%?>) :: HoistError m t e e' => t a -> (e -> e') -> m a
- Control.Monad.Error.Hoist: (<?>) :: HoistError m t e e' => t α -> e' -> m α
+ Control.Monad.Error.Hoist: (<?>) :: HoistError m t e e' => t a -> e' -> m a
- Control.Monad.Error.Hoist: hoistError :: HoistError m t e e' => (e -> e') -> t α -> m α
+ Control.Monad.Error.Hoist: hoistError :: HoistError m t e e' => (e -> e') -> t a -> m a
Files
- changelog.md +5/−0
- hoist-error.cabal +1/−1
- src/Control/Monad/Error/Hoist.hs +65/−50
changelog.md view
@@ -1,3 +1,8 @@+0.2.1.0++* Removed unicode syntax and variables+* Added Control.Monad.Error.Hoist.hoistErrorM (= flip (<%!?>))+ 0.2.0.1 * Import `eitherT` when using old EitherT instance.
hoist-error.cabal view
@@ -1,5 +1,5 @@ name: hoist-error-version: 0.2.0.1+version: 0.2.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
src/Control/Monad/Error/Hoist.hs view
@@ -3,7 +3,7 @@ {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE UnicodeSyntax #-}+ -- | 'HoistError' extends 'MonadError' with 'hoistError', which enables lifting -- of partiality types such as 'Maybe' and @'Either' e@ into the monad. --@@ -34,6 +34,7 @@ module Control.Monad.Error.Hoist ( HoistError(..)+ , hoistErrorM , (<%?>) , (<%!?>) , (<?>)@@ -63,95 +64,109 @@ -- information carried by the partiality type @t@, and @e'@ represents the type -- of error expected in the monad @m@. ---class Monad m ⇒ HoistError m t e e' | t → e where+class Monad m => HoistError m t e e' | t -> e where - -- | Given a conversion from the error in @t α@ to @e'@, we can hoist the+ -- | Given a conversion from the error in @t a@ to @e'@, we can hoist the -- computation into @m@. -- -- @- -- hoistError :: 'MonadError' e m -> (() -> e) -> 'Maybe' a -> m a- -- hoistError :: 'MonadError' e m -> (a -> e) -> 'Either' a b -> m b- -- hoistError :: 'MonadError' e m -> (a -> e) -> 'ExceptT' a m b -> m b+ -- 'hoistError' :: 'MonadError' e m -> (() -> e) -> 'Maybe' a -> m a+ -- 'hoistError' :: 'MonadError' e m -> (a -> e) -> 'Either' a b -> m b+ -- 'hoistError' :: 'MonadError' e m -> (a -> e) -> 'ExceptT' a m b -> m b -- @ hoistError- ∷ (e → e')- → t α- → m α+ :: (e -> e')+ -> t a+ -> m a -instance MonadError e m ⇒ HoistError m Maybe () e where+instance MonadError e m => HoistError m Maybe () e where hoistError f = maybe (throwError $ f ()) return -instance MonadError e' m ⇒ HoistError m (Either e) e e' where+instance MonadError e' m => HoistError m (Either e) e e' where hoistError f = either (throwError . f) return #if MIN_VERSION_either(5,0,0) -- Control.Monad.Trans.Either was removed from @either@ in version 5. #else-instance (m ~ n, MonadError e' m) ⇒ HoistError m (EitherT e n) e e' where+instance (m ~ n, MonadError e' m) => HoistError m (EitherT e n) e e' where hoistError f = eitherT (throwError . f) return #endif #if MIN_VERSION_mtl(2,2,2)-instance MonadError e' m ⇒ HoistError m (Except e) e e' where+instance MonadError e' m => HoistError m (Except e) e e' where hoistError f = either (throwError . f) return . runExcept -instance MonadError e' m ⇒ HoistError m (ExceptT e m) e e' where+instance MonadError e' m => HoistError m (ExceptT e m) e e' where hoistError f = either (throwError . f) return <=< runExceptT #else -- 'ErrorT' was renamed to 'ExceptT' in mtl 2.2.2-instance MonadError e' m ⇒ HoistError m (ErrorT e m) e e' where+instance MonadError e' m => HoistError m (ErrorT e m) e e' where hoistError f = either (throwError . f) return <=< runErrorT #endif +-- | A version of 'hoistError' that operates on values already in the monad.+--+-- @+-- 'hoistErrorM' :: 'MonadError' e m => (() -> e) -> m ('Maybe' a) -> m a+-- 'hoistErrorM' :: 'MonadError' e m => (a -> e) -> m ('Either' a b) -> m b+-- 'hoistErrorM' :: 'MonadError' e m => (a -> e) -> 'ExceptT' a m b -> 'ExceptT' a m b+-- @+hoistErrorM+ :: HoistError m t e e'+ => (e -> e')+ -> m (t a)+ -> m a+hoistErrorM e m = do+ x <- m+ hoistError e x+ -- | A flipped synonym for 'hoistError'. -- -- @--- '<%?>' :: 'MonadError' e m => 'Maybe' a -> (() -> e) -> m a--- '<%?>' :: 'MonadError' e m => 'Either' a b -> (a -> e) -> m b--- '<%?>' :: 'MonadError' e m => 'ExceptT' a m b -> (a -> e) -> 'ExceptT' a m b+-- ('<%?>') :: 'MonadError' e m => 'Maybe' a -> (() -> e) -> m a+-- ('<%?>') :: 'MonadError' e m => 'Either' a b -> (a -> e) -> m b+-- ('<%?>') :: 'MonadError' e m => 'ExceptT' a m b -> (a -> e) -> 'ExceptT' a m b -- @ (<%?>)- ∷ HoistError m t e e'- ⇒ t α- → (e → e')- → m α+ :: HoistError m t e e'+ => t a+ -> (e -> e')+ -> m a (<%?>) = flip hoistError infixl 8 <%?> {-# INLINE (<%?>) #-} --- | A version of '<%?>' that operates on values already in the monad.+-- | A flipped synonym for 'hoistErrorM'. -- -- @--- '<%!?>' :: 'MonadError' e m => m ('Maybe' a) -> (() -> e) -> m a--- '<%!?>' :: 'MonadError' e m => m ('Either' a b) -> (a -> e) -> m b--- '<%!?>' :: 'MonadError' e m => 'ExceptT' a m b -> (a -> e) -> 'ExceptT' a m b+-- ('<%!?>') :: 'MonadError' e m => m ('Maybe' a) -> (() -> e) -> m a+-- ('<%!?>') :: 'MonadError' e m => m ('Either' a b) -> (a -> e) -> m b+-- ('<%!?>') :: 'MonadError' e m => 'ExceptT' a m b -> (a -> e) -> 'ExceptT' a m b -- @ (<%!?>)- ∷ HoistError m t e e'- ⇒ m (t α)- → (e → e')- → m α-m <%!?> e = do- x ← m- x <%?> e+ :: HoistError m t e e'+ => m (t a)+ -> (e -> e')+ -> m a+(<%!?>) = flip hoistErrorM infixl 8 <%!?> {-# INLINE (<%!?>) #-} --- | A version of 'hoistError' that ignores the error in @t α@ and replaces it--- with a new one in @e'@.+-- | A version of '<%?>' that ignores the error in @t a@ and replaces it+-- with a new one. -- -- @--- '<?>' :: 'MonadError' e m => 'Maybe' a -> e -> m a--- '<?>' :: 'MonadError' e m => 'Either' a b -> e -> m b--- '<?>' :: 'MonadError' e m => 'ExceptT' a m b -> e -> 'ExceptT' a m b+-- ('<?>') :: 'MonadError' e m => 'Maybe' a -> e -> m a+-- ('<?>') :: 'MonadError' e m => 'Either' a b -> e -> m b+-- ('<?>') :: 'MonadError' e m => 'ExceptT' a m b -> e -> 'ExceptT' a m b -- @ (<?>)- ∷ HoistError m t e e'- ⇒ t α- → e'- → m α+ :: HoistError m t e e'+ => t a+ -> e'+ -> m a m <?> e = m <%?> const e infixl 8 <?>@@ -160,17 +175,17 @@ -- | A version of '<?>' that operates on values already in the monad. -- -- @--- '<!?>' :: 'MonadError' e m => m ('Maybe' a) -> e -> m a--- '<!?>' :: 'MonadError' e m => m ('Either' a b) -> e -> m b--- '<!?>' :: 'MonadError' e m => 'ExceptT' a m b -> e -> 'ExceptT' a m b+-- ('<!?>') :: 'MonadError' e m => m ('Maybe' a) -> e -> m a+-- ('<!?>') :: 'MonadError' e m => m ('Either' a b) -> e -> m b+-- ('<!?>') :: 'MonadError' e m => 'ExceptT' a m b -> e -> 'ExceptT' a m b -- @ (<!?>)- ∷ HoistError m t e e'- ⇒ m (t α)- → e'- → m α+ :: HoistError m t e e'+ => m (t a)+ -> e'+ -> m a m <!?> e = do- x ← m+ x <- m x <?> e infixl 8 <!?>