module Control.Monad.Failure.Class where
import Control.Exception (throw, Exception)
import Data.Typeable
class Monad m => MonadFailure e m where
failure :: e -> m a
class MonadFailure e m => WrapFailure e m where
wrapFailure :: (forall eIn. Exception eIn => eIn -> e) -> m a -> m a
instance MonadFailure e Maybe where failure _ = Nothing
instance MonadFailure e [] where failure _ = []
instance Exception e => MonadFailure e IO where
failure = Control.Exception.throw
failureString :: MonadFailure StringException m => String -> m a
failureString = failure . StringException
newtype StringException = StringException String
deriving Typeable
instance Show StringException where
show (StringException s) = "StringException: " ++ s
instance Exception StringException