mirror of
https://git.nerfingen.de/nerf/choirMail.git
synced 2025-06-08 09:41:00 +00:00
some error handling and cleanup that comes with it
This commit is contained in:
parent
99ab66b419
commit
616fc48990
7 changed files with 91 additions and 31 deletions
36
app/Monad.hs
Normal file
36
app/Monad.hs
Normal file
|
@ -0,0 +1,36 @@
|
|||
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
|
||||
module Monad(
|
||||
App
|
||||
,module Control.Monad.Fail
|
||||
,module Control.Monad.IO.Class
|
||||
,throwE
|
||||
,except
|
||||
,runApp
|
||||
) where
|
||||
|
||||
import qualified Control.Monad.Trans.Except as T
|
||||
import Control.Monad.Fail
|
||||
import Control.Monad.IO.Class
|
||||
|
||||
|
||||
-- We need this type isomorphism, because we want a different
|
||||
-- MonadFail implementation, if someone knows how to do this
|
||||
-- without writing the isomorphism out explicitly for all
|
||||
-- the other instances, (or without scary GeneralisedNewtypeDeriving)
|
||||
-- I would be happy
|
||||
newtype App a = App { runApp' :: T.ExceptT String IO a}
|
||||
deriving (Functor, Applicative, Monad, MonadIO)
|
||||
|
||||
instance MonadFail App where
|
||||
fail = throwE
|
||||
|
||||
-- reimplementing ExceptT interface
|
||||
-- I would love not to have to do this but I don't know how
|
||||
throwE :: String -> App a
|
||||
throwE = App . T.throwE
|
||||
|
||||
except :: Either String a -> App a
|
||||
except = App . T.except
|
||||
|
||||
runApp :: App a -> IO (Either String a)
|
||||
runApp = T.runExceptT . runApp'
|
Loading…
Add table
Add a link
Reference in a new issue