summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Infra/UseIO.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/GF/Infra/UseIO.hs')
-rw-r--r--src/compiler/GF/Infra/UseIO.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/compiler/GF/Infra/UseIO.hs b/src/compiler/GF/Infra/UseIO.hs
index 756df0679..2fdc42d83 100644
--- a/src/compiler/GF/Infra/UseIO.hs
+++ b/src/compiler/GF/Infra/UseIO.hs
@@ -32,6 +32,7 @@ import System.CPUTime
import System.Cmd
import Text.Printf
import Control.Monad
+import Control.Monad.Trans(MonadIO(..))
import Control.Exception(evaluate)
import qualified Data.ByteString.Char8 as BS
@@ -126,10 +127,7 @@ putStrLnFlush s = putStrLn s >> hFlush stdout
-- * IO monad with error; adapted from state monad
-newtype IOE a = IOE (IO (Err a))
-
-appIOE :: IOE a -> IO (Err a)
-appIOE (IOE iea) = iea
+newtype IOE a = IOE { appIOE :: IO (Err a) }
ioe :: IO (Err a) -> IOE a
ioe = IOE
@@ -140,6 +138,9 @@ ioeIO io = ioe (io >>= return . return)
ioeErr :: Err a -> IOE a
ioeErr = ioe . return
+ioeErrIn :: String -> IOE a -> IOE a
+ioeErrIn msg (IOE ioe) = IOE (fmap (errIn msg) ioe)
+
instance Functor IOE where fmap = liftM
instance Monad IOE where
@@ -149,6 +150,8 @@ instance Monad IOE where
appIOE $ err ioeBad f x -- f :: a -> IOE a
fail = ioeBad
+instance MonadIO IOE where liftIO = ioeIO
+
ioeBad :: String -> IOE a
ioeBad = ioe . return . Bad