Skip to content

Commit

Permalink
Move error msg into extractSuffixes and drop typeSig; use throwLeft
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Oct 21, 2024
1 parent 400918c commit 125355a
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions brat/Brat/Checker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,14 @@ checkIO tm@(WC fc _) exps acts wireFn errMsg = do
let (rows, rest) = extractSuffixes exps acts
localFC fc $ forM rows $ \(e:|exps, a:|acts) ->
wrapError (addRowContext (showRow $ e:exps) (showRow $ a:acts)) $ wireFn e a
case rest of
Left rest -> pure rest
Right (u:|unfilled) -> typeErr $ errMsg ++ showRow (u:unfilled) ++ " for " ++ show tm
throwLeft rest
where
addRowContext :: String -> String -> Error -> Error
addRowContext exp act = \case
(Err fc (TypeMismatch tm _ _)) -> Err fc $ TypeMismatch tm exp act
e -> e
extractSuffixes :: [a] -> [b] -> ([(NonEmpty a, NonEmpty b)], Either [a] (NonEmpty b))
extractSuffixes as [] = ([], Left as)
extractSuffixes [] (b:bs) = ([], Right (b:|bs))
extractSuffixes as [] = ([], Right as)
extractSuffixes [] bs = ([], Left $ TypeErr $ errMsg ++ showRow bs ++ " for " ++ show tm)
extractSuffixes (a:as) (b:bs) = first ((a:|as,b:|bs):) $ extractSuffixes as bs

checkInputs :: forall m d . (CheckConstraints m KVerb, ?my :: Modey m)
Expand Down

0 comments on commit 125355a

Please sign in to comment.