Explicit instance of MonadError for Tx

This commit is contained in:
Nikita Volkov 2014-12-27 20:38:41 +03:00
parent c02ba95858
commit 073acd578d

View File

@ -192,8 +192,32 @@ session pool m =
-- an unpredictable amount of times as well,
-- which, chances are, is not what you want.
newtype Tx c s r =
Tx (EitherT (TxError c) (Bknd.Tx c) r)
deriving (Functor, Applicative, Monad, MonadError (TxError c))
Tx { unwrapTx :: EitherT (TxError c) (Bknd.Tx c) r }
deriving (Functor, Applicative, Monad)
instance MonadError (TxError c) (Tx c s) where
throwError =
\case
BackendTxError e ->
Tx $ lift $ throwError e
e ->
Tx $ throwError e
catchError m h =
Tx $
let
m1 =
let
m2 =
runEitherT $ unwrapTx $ m
h2 =
return . Left . BackendTxError
in
EitherT $ catchError m2 h2
h1 =
unwrapTx . h
in
catchError m1 h1
data TxError c =
-- |