From 713e883ad7816f0bb0e3cb7f3cb8fc2a636c805b Mon Sep 17 00:00:00 2001 From: hallgren Date: Mon, 28 Jan 2013 16:12:56 +0000 Subject: Better error message for Predef.error + Instead of "Internal error in ...", you now get a proper error message with a source location and a function name. + Also added some missing error value propagation in the partial evaluator. + Also some other minor cleanup and error handling fixes. --- src/compiler/GF/Infra/UseIO.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/compiler/GF/Infra/UseIO.hs') 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 -- cgit v1.2.3