summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Infra/CheckM.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2013-11-20 00:45:33 +0000
committerhallgren <hallgren@chalmers.se>2013-11-20 00:45:33 +0000
commit018c9838ed31571b699118ae75b1d62d5527fd77 (patch)
treee3ff7163a838915020f2a1e355c984d22df7ad9c /src/compiler/GF/Infra/CheckM.hs
parentddac5f9e5aa935f4c154253831a36e49a48cdc8d (diff)
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.
Diffstat (limited to 'src/compiler/GF/Infra/CheckM.hs')
-rw-r--r--src/compiler/GF/Infra/CheckM.hs12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/compiler/GF/Infra/CheckM.hs b/src/compiler/GF/Infra/CheckM.hs
index 2f8a842e5..f1d4ebbde 100644
--- a/src/compiler/GF/Infra/CheckM.hs
+++ b/src/compiler/GF/Infra/CheckM.hs
@@ -15,7 +15,7 @@
module GF.Infra.CheckM
(Check, CheckResult, Message, runCheck,
checkError, checkCond, checkWarn, checkWarnings, checkAccumError,
- checkErr, checkIn, checkMap, checkMapRecover,
+ {-checkErr,-} checkIn, checkMap, checkMapRecover,
parallelCheck, accumulateError, commitCheck,
) where
@@ -92,14 +92,14 @@ commitCheck c =
list = vcat . reverse
-- | Run an error check, report errors and warnings
-runCheck :: Check a -> Err (a,String)
+runCheck :: ErrorMonad m => Check a -> m (a,String)
runCheck c =
case unCheck c {-[]-} ([],[]) of
- (([],ws),Success v) -> Ok (v,render (list ws))
+ (([],ws),Success v) -> return (v,render (list ws))
(msgs ,Success v) -> bad msgs
((es,ws),Fail e) -> bad ((e:es),ws)
where
- bad (es,ws) = Bad (render $ list ws $$ list es)
+ bad (es,ws) = raise (render $ list ws $$ list es)
list = vcat . reverse
parallelCheck :: [Check a] -> Check [a]
@@ -135,10 +135,6 @@ checkMapRecover f mp = do
return (Map.fromAscList kx)
-}
-checkErr :: Err a -> Check a
-checkErr (Ok x) = return x
-checkErr (Bad err) = checkError (text err)
-
checkIn :: Doc -> Check a -> Check a
checkIn msg c = Check $ \{-ctxt-} msgs0 ->
case unCheck c {-ctxt-} ([],[]) of