Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Dec 9, 2024
2 parents 837eeed + 05310cc commit 722e610
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions brat/Brat/Checker/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ import Bwd
import Hasochism
import Util (log2)

import Control.Monad.State.Lazy (StateT(..), runStateT)
import Control.Monad.Freer (req)
import Data.Bifunctor
import Data.Foldable (foldrM)
import Data.List (partition)
import Data.Type.Equality (TestEquality(..), (:~:)(..))
import qualified Data.Map as M
import Prelude hiding (last)
Expand Down Expand Up @@ -107,27 +109,21 @@ pullPortsSig :: Show ty
-> Checking [(PortName, ty)]
pullPortsSig = pullPorts id showSig

pullPorts :: forall a ty. Show ty
=> (a -> PortName) -- A way to get a port name for each element
pullPorts :: forall a ty

Check warning on line 112 in brat/Brat/Checker/Helpers.hs

View workflow job for this annotation

GitHub Actions / build

Unused quantified type variable ‘ty’

Check warning on line 112 in brat/Brat/Checker/Helpers.hs

View workflow job for this annotation

GitHub Actions / build

Unused quantified type variable ‘ty’
. (a -> PortName) -- A way to get a port name for each element
-> ([(a, ty)] -> String) -- A way to print the list
-> [PortName] -- Things to pull to the front
-> [(a, ty)] -- The list to rearrange
-> Checking [(a, ty)]
pullPorts _ _ [] types = pure types
pullPorts toPort showFn (p:ports) types = do
(x, types) <- pull1Port p types
(x:) <$> pullPorts toPort showFn ports types
pullPorts toPort showFn to_pull types =
-- the "state" here is the things still available to be pulled
(\(pulled, rest) -> pulled ++ rest) <$> runStateT (mapM pull1Port to_pull) types

Check warning on line 120 in brat/Brat/Checker/Helpers.hs

View workflow job for this annotation

GitHub Actions / hlint

Suggestion in pullPorts in module Brat.Checker.Helpers: Use uncurry ▫︎ Found: "\\ (pulled, rest) -> pulled ++ rest" ▫︎ Perhaps: "uncurry (++)" ▫︎ Note: increases laziness
where
pull1Port :: PortName
-> [(a, ty)]
-> Checking ((a, ty), [(a, ty)])
pull1Port p [] = fail $ "Port not found: " ++ p ++ " in " ++ showFn types
pull1Port p (x@(a,_):xs)
| p == toPort a
= if p `elem` (toPort . fst <$> xs)
then err (AmbiguousPortPull p (showFn (x:xs)))
else pure (x, xs)
| otherwise = second (x:) <$> pull1Port p xs
pull1Port :: PortName -> StateT [(a, ty)] Checking (a, ty)
pull1Port p = StateT $ \available -> case partition ((== p) . toPort . fst) available of
([], _) -> err $ BadPortPull $ "Port not found: " ++ p ++ " in " ++ showFn available
([found], remaining) -> pure (found, remaining)
(_, _) -> err $ AmbiguousPortPull p (showFn available)

ensureEmpty :: Show ty => String -> [(NamedPort e, ty)] -> Checking ()
ensureEmpty _ [] = pure ()
Expand Down

0 comments on commit 722e610

Please sign in to comment.