packages feed

hoist-error 0.1.0.2 → 0.2.0.0

raw patch · 3 files changed

+132/−21 lines, 3 filesdep ~basedep ~eitherdep ~mtlnew-uploaderPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, either, mtl

API changes (from Hackage documentation)

- Control.Monad.Error.Hoist: instance (m ~ n, MonadError e' m) => HoistError m (EitherT e n) e e'
- Control.Monad.Error.Hoist: instance MonadError e m => HoistError m Maybe () e
- Control.Monad.Error.Hoist: instance MonadError e' m => HoistError m (Either e) e e'
+ Control.Monad.Error.Hoist: infixl 8 <!?>
+ Control.Monad.Error.Hoist: instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Hoist.HoistError m GHC.Base.Maybe () e
+ Control.Monad.Error.Hoist: instance Control.Monad.Error.Class.MonadError e' m => Control.Monad.Error.Hoist.HoistError m (Control.Monad.Trans.Error.ErrorT e m) e e'
+ Control.Monad.Error.Hoist: instance Control.Monad.Error.Class.MonadError e' m => Control.Monad.Error.Hoist.HoistError m (Data.Either.Either e) e e'

Files

+ changelog.md view
@@ -0,0 +1,16 @@+0.2.0.0++* Trying to make things agreeable for removed modules (Control.Monad.Trans.Either) and new instances (Control.Monad.Except(T)).+* Applied the stylish-haskell hammer, and may remove unicode syntax for the proper hackage release.+* Update readme, added tested-with to cabal file to prepare for travis CI integration.+* Added travis yaml, and tested-with to cabal.+* Updated gitignore file.+* Removed 7.6 from tested GHC versions, and removed a command from travis to change to a directory that doesn't exist.+* Moved the lower bound of mtl to 2.1 to permit building using transformers 0.3 for slightly older GHC versions.+* Added CPP to not include Except instances unless MTL is min version 2.2.2. Added generous bounds to either package.+* Add ErrorT instance for pre-mtl-2.2.2.+* Added concrete type examples to Haddock, ala lens examples.++0.1.0.0++* Actually add the code
hoist-error.cabal view
@@ -1,24 +1,35 @@ name:                hoist-error-version:             0.1.0.2+version:             0.2.0.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 license-file:        LICENSE author:              Jon Sterling-maintainer:          jon@jonmsterling.com+maintainer:          sean.chalmers@data61.csiro.au copyright:           Copyright (c) 2014 AlephCloud, Inc category:            Control build-type:          Simple cabal-version:       >=1.10 +extra-source-files:  changelog.md++tested-with:         GHC == 7.8.4+                   , GHC == 7.10.3+                   , GHC == 8.0.2+                   , GHC == 8.2.2+                   , GHC == 8.4.1+++ source-repository head     type: git     location: https://github.com/alephcloud/hs-hoist-error.git  library   exposed-modules:     Control.Monad.Error.Hoist-  build-depends:       base >=4.7 && <4.8-                     , mtl >=2.2.1-                     , either+  build-depends:       base >=4.7 && <4.12+                     , mtl >2.1 && <2.3+                     , either >4 && <6+   hs-source-dirs:      src   default-language:    Haskell2010-
src/Control/Monad/Error/Hoist.hs view
@@ -1,22 +1,63 @@-{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE CPP                    #-}+{-# LANGUAGE FlexibleInstances      #-} {-# LANGUAGE FunctionalDependencies #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE UnicodeSyntax #-}+{-# 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.+--+-- For example, consider the following @App@ monad that may throw @BadPacket@+-- errors:+--+-- @+-- data AppError = BadPacket 'String'+--+-- newtype App a = App ('EitherT' AppError 'IO') a+--  deriving ('Functor', 'Applicative', 'Monad', 'MonadError' AppError, 'MonadIO')+-- @+--+-- We may have an existing function that parses a 'String' into a @'Maybe' Packet@+--+-- @+-- parsePacket :: 'String' -> 'Maybe' Packet+-- @+--+-- which can be lifted into the @App@ monad with 'hoistError'+--+-- @+-- appParsePacket :: 'String' -> 'App' Packet+-- appParsePacket s = 'hoistError' (\\() -> BadPacket "no parse") (parsePacket s)+-- @+--+-- Similar instances exist for @'Either' e@ and @'EitherT' e m@.  module Control.Monad.Error.Hoist-( HoistError(..)-, (<%?>)-, (<%!?>)-, (<?>)-, (<!?>)-) where+  ( HoistError(..)+  , (<%?>)+  , (<%!?>)+  , (<?>)+  , (<!?>)+  ) where -import Control.Monad.Error.Class-import Control.Monad.Trans.Either+import           Control.Monad              ((<=<))+import           Control.Monad.Error.Class  (MonadError (..)) -import Control.Monad.Trans+import           Data.Either                (Either, either) +#if MIN_VERSION_mtl(2,2,2)+import           Control.Monad.Except       (Except, ExceptT, runExcept,+                                             runExceptT)+#else+import           Control.Monad.Error        (Error, ErrorT, runErrorT)+#endif++#if MIN_VERSION_either(5,0,0)+-- Control.Monad.Trans.Either was removed from @either@ in version 5.+#else+import           Control.Monad.Trans.Either (EitherT, runEitherT)+#endif+ -- | A tricky class for easily hoisting errors out of partiality types (e.g. -- 'Maybe', @'Either' e@) into a monad. The parameter @e@ represents the error -- information carried by the partiality type @t@, and @e'@ represents the type@@ -27,6 +68,11 @@   -- | Given a conversion from the error in @t α@ 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     ∷ (e → e')     → t α@@ -38,10 +84,32 @@ 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   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+  hoistError f = either (throwError . f) return . runExcept++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+  hoistError f = either (throwError . f) return <=< runErrorT+#endif+ -- | 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+-- @ (<%?>)   ∷ HoistError m t e e'   ⇒ t α@@ -54,6 +122,11 @@  -- | 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) -> (a  -> e) ->             m b+-- '<%!?>' :: 'MonadError' e m =>    'ExceptT' a m b  -> (a  -> e) -> 'ExceptT' a m b+-- @ (<%!?>)   ∷ HoistError m t e e'   ⇒ m (t α)@@ -66,9 +139,14 @@ infixl 8 <%!?> {-# INLINE (<%!?>) #-} --- | A version of @hoistError@ that ignores the error in @t α@ and replaces it+-- | A version of 'hoistError' that ignores the error in @t α@ and replaces it -- with a new one in @e'@. --+-- @+-- '<?>' :: '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 α@@ -79,7 +157,13 @@ infixl 8 <?> {-# INLINE (<?>) #-} --- | A version of @<?>@ that operates on values already in the monad.+-- | 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+-- @ (<!?>)   ∷ HoistError m t e e'   ⇒ m (t α)