Revision fb54b24a
b/src/Ganeti/BasicTypes.hs | ||
---|---|---|
56 | 56 |
) where |
57 | 57 |
|
58 | 58 |
import Control.Applicative |
59 |
import Control.Exception (try) |
|
59 | 60 |
import Control.Monad |
60 | 61 |
import Control.Monad.Error.Class |
61 | 62 |
import Control.Monad.Trans |
... | ... | |
157 | 158 |
instance MonadTrans (ResultT a) where |
158 | 159 |
lift = ResultT . liftM Ok |
159 | 160 |
|
161 |
-- | The instance catches any 'IOError' using 'try' and converts it into an |
|
162 |
-- error message using 'strMsg'. |
|
163 |
-- |
|
164 |
-- This way, monadic code within 'ResultT' that uses solely 'liftIO' to |
|
165 |
-- include 'IO' actions ensures that all IO exceptions are handled. |
|
166 |
-- |
|
167 |
-- Other exceptions (see instances of 'Exception') are not currently handled. |
|
168 |
-- This might be revised in the future. |
|
160 | 169 |
instance (MonadIO m, Error a) => MonadIO (ResultT a m) where |
161 |
liftIO = lift . liftIO |
|
170 |
liftIO = ResultT . liftIO |
|
171 |
. liftM (either (failError . show) return) |
|
172 |
. (try :: IO a -> IO (Either IOError a)) |
|
162 | 173 |
|
163 | 174 |
instance (Monad m, Error a, Monoid a) => MonadPlus (ResultT a m) where |
164 | 175 |
mzero = ResultT $ return mzero |
Also available in: Unified diff