on master help sign in
MonadExcept instance for WrappedEther
commit0f9f8fc0d93deb09df5849c900d9420ff8248600 authorIndex Int <vlad.z.4096@gmail.com> dateFri 12 Jun 2015, 02:00 (11 years ago) parent5289d99
2 files changed+9
src/Control/Ether/Wrapped.hs+6 src/Control/Monad/Ether/Except.hs+3
src/Control/Ether/Wrapped.hs+6
@@ -13,9 +13,11 @@ import Control.Monad.Fix (MonadFix)
1313import Control.Monad.IO.Class (MonadIO)
1414import Control.Monad.Ether.Reader
1515import Control.Monad.Ether.State
16+import Control.Monad.Ether.Except
1617
1718import qualified Control.Monad.Reader as Class
1819import qualified Control.Monad.State as Class
20+import qualified Control.Monad.Except as Class
1921
2022newtype WrappedEther tag m a = WrapEther { unwrapEther :: m a }
2123 deriving ( Functor, Applicative, Alternative, Monad, MonadPlus
@@ -29,5 +31,9 @@ instance MonadState tag s m => Class.MonadState s (WrappedEther tag m) where
2931 get = WrapEther $ get (Proxy :: Proxy tag)
3032 put = WrapEther . put (Proxy :: Proxy tag)
3133
34+instance MonadExcept tag e m => Class.MonadError e (WrappedEther tag m) where
35+ throwError = WrapEther . throw (Proxy :: Proxy tag)
36+ catchError m h = WrapEther $ catch (Proxy :: Proxy tag) (unwrapEther m) (unwrapEther . h)
37+
3238ethered :: proxy tag -> WrappedEther tag m a -> m a
3339ethered _proxy = unwrapEther
src/Control/Monad/Ether/Except.hs+3
@@ -44,8 +44,11 @@ import qualified Control.Monad.Trans.Writer.Strict as Trans.W.Strict
4444
4545class Monad m => MonadExcept tag e m | m tag -> e where
4646
47+ -- | Is used within a monadic computation to begin exception processing.
4748 throw :: proxy tag -> e -> m a
4849
50+ -- | A handler function to handle previous exceptions and return to
51+ -- normal execution.
4952 catch :: proxy tag -> m a -> (e -> m a) -> m a
5053
5154instance {-# OVERLAPPING #-} Monad m => MonadExcept tag e (ExceptT tag e m) where