packages feed

attempt 0.0.2 → 0.2.0

raw patch · 3 files changed

+17/−101 lines, 3 filesdep +failuredep −control-monad-failuredep −monadlocdep −transformers

Dependencies added: failure

Dependencies removed: control-monad-failure, monadloc, transformers

Files

− Control/Monad/Attempt.hs
@@ -1,69 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}---------------------------------------------------------------- Module        : Control.Monad.Attempt--- Copyright     : Michael Snoyman--- License       : BSD3------ Maintainer    : Michael Snoyman <michael@snoyman.com>--- Stability     : Unstable--- Portability   : portable----------------------------------------------------------------- | Provide a monad transformer for the attempt monad, which allows the--- reporting of errors using extensible exceptions.-module Control.Monad.Attempt-    ( AttemptT (..)-    , evalAttemptT-    , module Data.Attempt-    ) where--import Data.Attempt-import Control.Applicative-import Control.Monad-import Control.Monad.Trans-import Control.Monad.Loc-import Control.Exception (Exception)--newtype AttemptT m v = AttemptT {-    runAttemptT :: m (Attempt v)-}--instance Monad m => Functor (AttemptT m) where-    fmap f = AttemptT . liftM (liftM f) . runAttemptT-instance Monad m => Applicative (AttemptT m) where-    pure = return-    (<*>) = ap-instance Monad m => Monad (AttemptT m) where-    return = AttemptT . return . return-    (AttemptT mv) >>= f = AttemptT $ do-        v <- mv-        attempt (return . failure) (runAttemptT . f) v-instance (Exception e, Monad m) => MonadFailure e (AttemptT m) where-    failure = AttemptT . return . failure-instance (Monad m, Exception e) => WrapFailure e (AttemptT m) where-    wrapFailure f (AttemptT mv) = AttemptT $ liftM (wrapFailure f) mv-instance MonadTrans AttemptT where-    lift = AttemptT . liftM return where-instance MonadIO m => MonadIO (AttemptT m) where-    liftIO = AttemptT . liftM return . liftIO where-instance Monad m => FromAttempt (AttemptT m) where-    fromAttempt = attempt failure return-instance MonadLoc m => MonadLoc (AttemptT m) where-    withLoc loc (AttemptT a) = AttemptT $ do-        current <- withLoc loc a-        return $ withLoc loc current---- | Instances of 'FromAttempt' specify a manner for embedding 'Attempt'--- failures directly into the target data type. For example, the 'IO' instance--- simply throws a runtime error. This is a convenience wrapper when you simply--- want to use that default action.------ So given a type 'AttemptT' 'IO' 'Int', this function will convert it to 'IO'--- 'Int', throwing any exceptions in the original value.-evalAttemptT :: (Monad m, FromAttempt m)-             => AttemptT m v-             -> m v-evalAttemptT = join . liftM fromAttempt . runAttemptT where
Data/Attempt.hs view
@@ -26,7 +26,6 @@     , FromAttempt (..)     , fa     , joinAttempt-    , monadicStackTrace       -- * General handling of 'Attempt's     , attempt     , makeHandler@@ -39,8 +38,8 @@     , successes     , failures     , partitionAttempts-      -- * Reexport the 'MonadFailure' class-    , module Control.Monad.Failure+      -- * Reexport the 'Failure' class+    , module Control.Failure     ) where  import qualified Control.Exception as E@@ -48,41 +47,36 @@ import Control.Applicative import Data.Generics import Data.Either (lefts)-import Control.Monad.Failure-import Control.Monad.Loc+import Control.Failure import GHC.Show (appPrec, appPrec1) -- | Contains either a 'Success' value or a 'Failure' exception. data Attempt v   = Success v-  | forall e. E.Exception e => Failure [String] e+  | forall e. E.Exception e => Failure e     deriving (Typeable)  instance Show v => Show (Attempt v) where   showsPrec p (Success v)     = showParen (p > appPrec) $ showString "Success " . showsPrec appPrec1 v-  showsPrec p (Failure st v)+  showsPrec p (Failure v)     = showParen (p > appPrec) $-        showString "Failure " . showsPrec appPrec1 st . showString " "-                              . showsPrec appPrec1 v+        showString "Failure " . showsPrec appPrec1 v  instance Functor Attempt where     fmap f (Success v) = Success $ f v-    fmap _ (Failure st e) = Failure st e+    fmap _ (Failure e) = Failure e instance Applicative Attempt where     pure = Success     (<*>) = ap instance Monad Attempt where     return = Success     (Success v) >>= f = f v-    (Failure st e) >>= _ = Failure st e-instance E.Exception e => MonadFailure e Attempt where-    failure = Failure []+    (Failure e) >>= _ = Failure e+instance E.Exception e => Failure e Attempt where+    failure = Failure instance E.Exception e => WrapFailure e Attempt where     wrapFailure _ (Success v) = Success v-    wrapFailure f (Failure st e) = Failure st $ f e-instance MonadLoc Attempt where-    withLoc _ (Success v) = Success v-    withLoc s (Failure st e) = Failure (s:st) e+    wrapFailure f (Failure e) = Failure $ f e  -- | Any type which can be converted from an 'Attempt'. The included instances are your \"usual suspects\" for dealing with error handling. They include: --@@ -125,12 +119,6 @@ joinAttempt :: (FromAttempt m, Monad m) => m (Attempt v) -> m v joinAttempt = (>>= fromAttempt) --- | Extra the monadic stack trace from the given 'Attempt' value. Returns the--- empty list when the given value is a 'Success'.-monadicStackTrace :: Attempt a -> [String]-monadicStackTrace (Success _) = []-monadicStackTrace (Failure st _) = st- -- | Process either the exception or value in an 'Attempt' to produce a result. -- -- This function is modeled after 'maybe' and 'either'. The first argument must@@ -147,7 +135,7 @@         -> Attempt a         -> b attempt _ f (Success v) = f v-attempt f _ (Failure _ e) = f e+attempt f _ (Failure e) = f e  -- | Convert multiple 'AttemptHandler's and a default value into an exception -- handler.
attempt.cabal view
@@ -1,13 +1,13 @@ name:            attempt-version:         0.0.2+version:         0.2.0 license:         BSD3 license-file:    LICENSE author:          Michael Snoyman, Nicolas Pouillard maintainer:      Michael Snoyman <michael@snoyman.com>-synopsis:        Error handling using extensible exceptions outside the IO monad.+synopsis:        Concrete data type for handling extensible exceptions as failures. description:     Defines a data type, Attempt, which has a Success and Failure constructor. Failure contains an extensible exception.-category:        Data-stability:       unstable+category:        Data, Failure+stability:       stable cabal-version:   >= 1.2 build-type:      Simple homepage:        http://github.com/snoyberg/attempt/tree/master@@ -15,9 +15,6 @@ library     build-depends:   base >= 4 && < 5,                      syb,-                     transformers >= 0.1.4.0,-                     control-monad-failure >= 0.4,-                     monadloc >= 0.4+                     failure >= 0.0.0 && < 0.1     exposed-modules: Data.Attempt-                     Control.Monad.Attempt     ghc-options:     -Wall