From 018c9838ed31571b699118ae75b1d62d5527fd77 Mon Sep 17 00:00:00 2001 From: hallgren Date: Wed, 20 Nov 2013 00:45:33 +0000 Subject: Reduced clutter in monadic code + Eliminated vairous ad-hoc coersion functions between specific monads (IO, Err, IOE, Check) in favor of more general lifting functions (liftIO, liftErr). + Generalized many basic monadic operations from specific monads to arbitrary monads in the appropriate class (MonadIO and/or ErrorMonad), thereby completely eliminating the need for lifting functions in lots of places. This can be considered a small step forward towards a cleaner compiler API and more malleable compiler code in general. --- src/compiler/GFC.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/compiler/GFC.hs') diff --git a/src/compiler/GFC.hs b/src/compiler/GFC.hs index f75a39ab1..dd9f1771b 100644 --- a/src/compiler/GFC.hs +++ b/src/compiler/GFC.hs @@ -55,9 +55,9 @@ compileSourceFiles opts fs = compileCFFiles :: Options -> [FilePath] -> IOE () compileCFFiles opts fs = - do s <- ioeIO $ fmap unlines $ mapM readFile fs + do s <- liftIO $ fmap unlines $ mapM readFile fs let cnc = justModuleName (last fs) - gf <- ioeErr $ getCF cnc s + gf <- getCF cnc s gr <- compileSourceGrammar opts gf if flag optStopAfterPhase opts == Compile then return () @@ -76,7 +76,7 @@ unionPGFFiles opts fs = then putStrLnE $ "Refusing to overwrite " ++ pgfFile else writePGF opts pgf writeOutputs opts pgf - where readPGFVerbose f = putPointE Normal opts ("Reading " ++ f ++ "...") $ ioeIO $ readPGF f + where readPGFVerbose f = putPointE Normal opts ("Reading " ++ f ++ "...") $ liftIO $ readPGF f writeOutputs :: Options -> PGF -> IOE () writeOutputs opts pgf = do @@ -93,7 +93,7 @@ writeByteCode opts pgf path = case flag optOutputDir opts of Nothing -> file Just dir -> dir file - in putPointE Normal opts ("Writing " ++ path ++ "...") $ ioeIO $ + in putPointE Normal opts ("Writing " ++ path ++ "...") $ liftIO $ bracket (openFile path WriteMode) (hClose) @@ -109,14 +109,14 @@ writeByteCode opts pgf writePGF :: Options -> PGF -> IOE () writePGF opts pgf = do let outfile = grammarName opts pgf <.> "pgf" - putPointE Normal opts ("Writing " ++ outfile ++ "...") $ ioeIO $ encodeFile outfile pgf + putPointE Normal opts ("Writing " ++ outfile ++ "...") $ liftIO $ encodeFile outfile pgf grammarName :: Options -> PGF -> String grammarName opts pgf = fromMaybe (showCId (absname pgf)) (flag optName opts) writeOutput :: Options -> FilePath-> String -> IOE () writeOutput opts file str = - putPointE Normal opts ("Writing " ++ path ++ "...") $ ioeIO $ + putPointE Normal opts ("Writing " ++ path ++ "...") $ liftIO $ writeUTF8File path str where path = maybe id () (flag optOutputDir opts) file -- cgit v1.2.3