Check monad: support for accumulated errors

In addition to warnings, the Check monad in GF.Infra.CheckM can now accumulate
errors. There are two new functions

	checkAccumError: Message -> Check ()
	accumulateError :: (a -> Check a) -> a -> Check a

The former (with the same type as checkWarn) is used to report an accumulated
(nonfatal) error. The latter converts fatal errors into accumulated errors.

Accumulated errors are reported as regular errors by runCheck.

Also, the Check monad type has been made abstract.
This commit is contained in:
hallgren
2012-06-25 14:01:58 +00:00
parent deec2d4ecf
commit 0a09f3e0b2
2 changed files with 58 additions and 30 deletions

View File

@@ -458,7 +458,7 @@ data MetaValue
type MetaStore = IntMap.IntMap MetaValue
data TcResult a
= TcOk a MetaStore [Message]
| TcFail [Message]
| TcFail [Message] -- First msg is error, the rest are warnings?
newtype TcM a = TcM {unTcM :: MetaStore -> [Message] -> TcResult a}
instance Monad TcM where
@@ -480,9 +480,9 @@ tcWarn :: Message -> TcM ()
tcWarn msg = TcM (\ms msgs -> TcOk () ms ((text "Warning:" <+> msg) : msgs))
runTcM :: TcM a -> Check a
runTcM f = Check (\ctxt msgs -> case unTcM f IntMap.empty msgs of
TcOk x _ msgs -> Success x msgs
TcFail msgs -> Fail msgs)
runTcM f = case unTcM f IntMap.empty [] of
TcOk x _ msgs -> do checkWarnings msgs; return x
TcFail (msg:msgs) -> do checkWarnings msgs; checkError msg
newMeta :: Sigma -> TcM MetaId
newMeta ty = TcM (\ms msgs ->