From c707575bd7751ac3b03371edba478e37d3488448 Mon Sep 17 00:00:00 2001 From: hallgren Date: Mon, 10 Nov 2014 16:20:01 +0000 Subject: Documentation improvements and cleanup relating to the IOE monad Renamed appIOE to tryIOE (it is analogous to 'try' in the standard libraries). Removed unused IOE operations & documented the remaining ones. Removed/simplified superfluous uses of IOE operations. --- src/compiler/GF/Infra/UseIO.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 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 b5ef38f49..14120d811 100644 --- a/src/compiler/GF/Infra/UseIO.hs +++ b/src/compiler/GF/Infra/UseIO.hs @@ -129,14 +129,16 @@ splitInModuleSearchPath s = case break isPathSep s of -- | Was: @newtype IOE a = IOE { appIOE :: IO (Err a) }@ type IOE a = IO a -ioe :: IO (Err a) -> IOE a -ioe io = err fail return =<< io +--ioe :: IO (Err a) -> IOE a +--ioe io = err fail return =<< io -appIOE :: IOE a -> IO (Err a) -appIOE ioe = handle (fmap Ok ioe) (return . Bad) +-- | Catch exceptions caused by calls to 'raise' or 'fail' in the 'IO' monad. +-- To catch all 'IO' exceptions, use 'try' instead. +tryIOE :: IOE a -> IO (Err a) +tryIOE ioe = handle (fmap Ok ioe) (return . Bad) -runIOE :: IOE a -> IO a -runIOE = id +--runIOE :: IOE a -> IO a +--runIOE = id -- instance MonadIO IOE where liftIO io = ioe (io >>= return . return) @@ -160,6 +162,8 @@ instance Monad IOE where appIOE $ err raise f x -- f :: a -> IOE a fail = raise -} + +-- | Print the error message and return a default value if the IO operation 'fail's useIOE :: a -> IOE a -> IO a useIOE a ioe = handle ioe (\s -> putStrLn s >> return a) -- cgit v1.2.3