Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] Common-up in checkBody #57

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions brat/Brat/Checker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -709,27 +709,23 @@
-> FunBody Term UVerb
-> CTy m Z -- Function type
-> Checking Src
checkBody fnName body cty = case body of
NoLhs tm -> do
((src, _), _) <- makeBox (fnName ++ ".box") cty $ \conns -> do
(((), ()), leftovers) <- check tm conns
checkConnectorsUsed (fcOf tm, fcOf tm) (show tm) conns leftovers
pure src
Clauses (c :| cs) -> do
fc <- req AskFC
((box, _), _) <- makeBox (fnName ++ ".box") cty $ \conns -> do
let tm = Lambda c cs
(((), ()), leftovers) <- check (WC fc tm) conns
checkConnectorsUsed (bimap fcOf fcOf c) (show tm) conns leftovers
pure box
Undefined -> err (InternalError "Checking undefined clause")
where
checkConnectorsUsed _ _ _ ([], []) = pure ()
checkConnectorsUsed (_, tmFC) tm (_, unders) ([], rightUnders) = localFC tmFC $
let numUsed = length unders - length rightUnders in
err (TypeMismatch tm (showRow unders) (showRow (take numUsed unders)))
checkConnectorsUsed (absFC, _) _ _ (rightOvers, _) = localFC absFC $
typeErr ("Inputs " ++ showRow rightOvers ++ " weren't used")
checkBody fnName body cty = do
(tm, (absFC, tmFC)) <- case body of
NoLhs tm -> pure (tm, (fcOf tm, fcOf tm))
Clauses (c :| cs) -> do
fc <- req AskFC
pure $ (WC fc (Lambda c cs), (bimap fcOf fcOf c))

Check warning on line 717 in brat/Brat/Checker.hs

View workflow job for this annotation

GitHub Actions / hlint

Suggestion in checkBody in module Brat.Checker: Redundant $ ▫︎ Found: "pure $ (WC fc (Lambda c cs), (bimap fcOf fcOf c))" ▫︎ Perhaps: "pure (WC fc (Lambda c cs), (bimap fcOf fcOf c))"

Check warning on line 717 in brat/Brat/Checker.hs

View workflow job for this annotation

GitHub Actions / hlint

Suggestion in checkBody in module Brat.Checker: Redundant bracket ▫︎ Found: "(WC fc (Lambda c cs), (bimap fcOf fcOf c))" ▫︎ Perhaps: "(WC fc (Lambda c cs), bimap fcOf fcOf c)"
Undefined -> err (InternalError "Checking undefined clause")
((src, _), _) <- makeBox (fnName ++ ".box") cty $ \conns@(_, unders) -> do
(((), ()), leftovers) <- check tm conns
case leftovers of
([], []) -> pure ()
([], rightUnders) -> localFC tmFC $
let numUsed = length unders - length rightUnders
in err (TypeMismatch (show tm) (showRow unders) (showRow (take numUsed unders)))
(rightOvers, _) -> localFC absFC $
typeErr ("Inputs " ++ showRow rightOvers ++ " weren't used")
pure src

-- Constructs row from a list of ends and types. Uses standardize to ensure that dependency is
-- detected. Fills in the first bot ends from a stack. The stack grows every time we go under
Expand Down
Loading