packages feed

failure 0.0.0.3 → 0.2.0.3

raw patch · 2 files changed

Files

Control/Failure.hs view
@@ -1,17 +1,16 @@-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} -- | Type classes for returning failures.+--+-- Note: This module used to contain a lot more functionality, but I believe it+-- was unused functionality. If you want any of it back, just email me. module Control.Failure-    ( -- * Type classes+    ( -- * Type class       Failure (..)-    , FunctorFailure-    , ApplicativeFailure-    , MonadFailure+      -- * General exceptions+    , exception+      {-       -- * Wrapping failures     , WrapFailure (..)       -- * Convenience 'String' failure@@ -21,25 +20,21 @@     , Try (..)     , NothingException (..)     , NullException (..)+      -}     ) where -import Prelude hiding (catch)-import Control.Exception (throw, catch, Exception, SomeException (..))-import Data.Typeable (Typeable)-import Control.Applicative (Applicative (..))+import Control.Exception (throwIO, Exception (toException), SomeException (..))+import Control.Monad.Trans.Error ()+import Control.Monad.Trans.Class (MonadTrans (lift)) -class Failure e f where+class Monad f => Failure e f where     failure :: e -> f v-class (Functor f, Failure e f) => FunctorFailure e f-class (Applicative f, Failure e f) => ApplicativeFailure e f-class (Monad f, Applicative f, Failure e f) => MonadFailure e f --- These introduce the need to use undecidables.--- However, since they are merely type class synonyms, this is acceptable.-instance (Functor f, Failure e f) => FunctorFailure e f-instance (Applicative f, Failure e f) => ApplicativeFailure e f-instance (Monad f, Applicative f, Failure e f) => MonadFailure e f+-- | Convert to a 'SomeException' via 'toException' before calling 'failure'.+exception :: (Exception e, Failure SomeException m) => e -> m a+exception = failure . toException +{- class Failure e f => WrapFailure e f where     -- | Wrap the failure value, if any, with the given function. This is     -- useful in particular when you want all the exceptions returned from a@@ -48,12 +43,12 @@     wrapFailure :: (forall eIn. Exception eIn => eIn -> e) -> f a -> f a instance Exception e => WrapFailure e IO where     wrapFailure f m =-        m `catch` \e@SomeException{} -> throw (f e)+        m `catch` \e@SomeException{} -> throwIO (f e)  class Try f where   type Error f   -- Turn a concrete failure into an abstract failure-  try :: ApplicativeFailure (Error f) f' => f a -> f' a+  try :: Failure (Error f) f' => f a -> f' a  -- | Call 'failure' with a 'String'. failureString :: Failure StringException m => String -> m a@@ -64,6 +59,7 @@ instance Show StringException where     show (StringException s) = "StringException: " ++ s instance Exception StringException+-}  -- -------------- -- base instances@@ -71,12 +67,19 @@  instance Failure e Maybe where failure _ = Nothing instance Failure e []    where failure _ = []+instance Failure e (Either e) where failure = Left  instance Exception e => Failure e IO where-  failure = Control.Exception.throw+  failure = throwIO -instance Failure e (Either e) where failure = Left+-- | Instance for all monad transformers, simply lift the @failure@ into the+-- base monad.+instance (MonadTrans t, Failure e m, Monad (t m)) => Failure e (t m) where+    failure = lift . failure +{-+-- not a monad or applicative instance Failure e (Either e) where failure = Left+ data NothingException = NothingException   deriving (Show, Typeable) instance Exception NothingException@@ -84,12 +87,12 @@ instance Try Maybe where   type Error Maybe = NothingException   try Nothing      = failure NothingException-  try (Just x)     = pure x+  try (Just x)     = return x  instance Try (Either e) where   type Error (Either e) = e   try (Left  e)         = failure e-  try (Right x)         = pure x+  try (Right x)         = return x  data NullException = NullException   deriving (Show, Typeable)@@ -98,4 +101,5 @@ instance Try [] where   type Error [] = NullException   try []        = failure NullException-  try (x:_)     = pure x+  try (x:_)     = return x+-}
failure.cabal view
@@ -1,19 +1,20 @@ name: failure-version: 0.0.0.3+version: 0.2.0.3 Cabal-Version:  >= 1.6 build-type: Simple-license: PublicDomain+license: BSD3 author: Pepe Iborra, Michael Snoyman, Nicolas Pouillard maintainer: pepeiborra@gmail.com-homepage: http://github.com/snoyberg/failure-description: A simple type class for success/failure computations.-synopsis: A simple type class for success/failure computations.+homepage: http://www.haskell.org/haskellwiki/Failure+description: Please switch to the exceptions package+synopsis: A simple type class for success/failure computations. (deprecated) category: Control, Monads, Failure stability: stable  Library   buildable: True-  build-depends: base >= 4 && < 5+  build-depends: base         >= 4   && < 5+               , transformers >= 0.2   ghc-options: -Wall    exposed-modules: