success 0.2.1.1 → 0.2.2
raw patch · 3 files changed
+59/−2 lines, 3 filesdep +monad-controldep +mtldep +transformersdep ~base
Dependencies added: monad-control, mtl, transformers, transformers-base
Dependency ranges changed: base
Files
- library/Success/Impure.hs +52/−0
- library/Success/Pure.hs +2/−1
- success.cabal +5/−1
library/Success/Impure.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE UndecidableInstances #-} -- | -- The types and functions are trivial and self-descriptive, -- hence this sentence is the sole documentation you get on them.@@ -12,6 +13,11 @@ import Prelude import Control.Applicative import Control.Monad+import Control.Monad.IO.Class+import Control.Monad.Error.Class+import Control.Monad.Trans.Class+import Control.Monad.Trans.Control+import Control.Monad.Base import qualified Success.Pure @@ -56,6 +62,52 @@ {-# INLINE mplus #-} mplus = (<|>)++instance (Applicative m, Monad m) => MonadError (Maybe a) (Success a m) where+ {-# INLINE throwError #-}+ throwError =+ Success . return . throwError+ {-# INLINE catchError #-}+ catchError (Success m) handler =+ Success $ m >>= either (unwrap . handler) (return . Success.Pure.success) . Success.Pure.asEither+ where+ unwrap (Success m) =+ m++instance MonadTrans (Success a) where+ {-# INLINE lift #-}+ lift =+ Success . liftM pure++instance (Applicative m, MonadIO m) => MonadIO (Success a m) where+ {-# INLINE liftIO #-}+ liftIO =+ lift . liftIO++instance (Applicative m, MonadBase n m) => MonadBase n (Success a m) where+ {-# INLINE liftBase #-}+ liftBase =+ lift . liftBase++instance MonadTransControl (Success a) where+ type StT (Success a) b =+ Success.Pure.Success a b+ {-# INLINE liftWith #-}+ liftWith onUnlift =+ lift $ onUnlift $ \(Success impl) -> impl+ {-# INLINE restoreT #-}+ restoreT =+ Success++instance (Applicative m, MonadBaseControl n m) => MonadBaseControl n (Success a m) where+ type StM (Success a m) b =+ ComposeSt (Success a) m b+ {-# INLINE liftBaseWith #-}+ liftBaseWith =+ defaultLiftBaseWith+ {-# INLINE restoreM #-}+ restoreM =+ defaultRestoreM {-# INLINE run #-} run :: Success e m a -> m (Success.Pure.Success e a)
library/Success/Pure.hs view
@@ -17,11 +17,12 @@ import Prelude import Control.Applicative import Control.Monad+import Control.Monad.Error.Class newtype Success a b = Success (Either (Maybe a) b)- deriving (Functor, Applicative, Monad)+ deriving (Functor, Applicative, Monad, MonadError (Maybe a), Show) instance Alternative (Success a) where {-# INLINE empty #-}
success.cabal view
@@ -1,7 +1,7 @@ name: success version:- 0.2.1.1+ 0.2.2 synopsis: A version of Either specialised for encoding of success or failure description:@@ -49,5 +49,9 @@ Success.Pure Success.Impure build-depends:+ transformers-base >= 0.4 && < 0.5,+ monad-control >= 1 && < 2,+ mtl >= 2 && < 3,+ transformers >= 0.3 && < 0.5, base >= 4.6 && < 5