From 37cfe3c0f4fb16189bbe3bb735f758cd6e3d9157 Mon Sep 17 00:00:00 2001 From: Krzysztof Gogolewski Date: Mon, 14 Nov 2022 19:30:50 +0100 Subject: Misc cleanup * Replace catMaybes . map f with mapMaybe f * Use concatFS to concatenate multiple FastStrings * Fix documentation of -exclude-module * Cleanup getIgnoreCount in GHCi.UI --- ghc/GHCi/UI.hs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'ghc') diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs index 3e1bc227d1..9327ac6da7 100644 --- a/ghc/GHCi/UI.hs +++ b/ghc/GHCi/UI.hs @@ -3864,7 +3864,7 @@ continueCmd argLine = withSandboxOnly ":continue" $ where contSwitch :: [String] -> Either SDoc (Maybe Int) contSwitch [ ] = Right Nothing - contSwitch [x] = getIgnoreCount x + contSwitch [x] = Just <$> getIgnoreCount x contSwitch _ = Left $ text "After ':continue' only one ignore count is allowed" @@ -3992,30 +3992,24 @@ ignoreCmd argLine = withSandboxOnly ":ignore" $ do result <- ignoreSwitch (words argLine) case result of Left sdoc -> printForUser sdoc - Right (loc, mbCount) -> do + Right (loc, count) -> do let breakInfo = GHC.BreakInfo (breakModule loc) (breakTick loc) - count = fromMaybe 0 mbCount setupBreakpoint breakInfo count -ignoreSwitch :: GhciMonad m => [String] -> m (Either SDoc (BreakLocation, Maybe Int)) +ignoreSwitch :: GhciMonad m => [String] -> m (Either SDoc (BreakLocation, Int)) ignoreSwitch [break, count] = do sdoc_loc <- getBreakLoc break pure $ (,) <$> sdoc_loc <*> getIgnoreCount count ignoreSwitch _ = pure $ Left $ text "Syntax: :ignore " -getIgnoreCount :: String -> Either SDoc (Maybe Int) +getIgnoreCount :: String -> Either SDoc Int getIgnoreCount str = - let checkJust :: Maybe Int -> Either SDoc (Maybe Int) - checkJust mbCnt - | (isJust mbCnt) = Right mbCnt - | otherwise = Left $ sdocIgnore <+> text "is not numeric" - checkPositive :: Maybe Int -> Either SDoc (Maybe Int) - checkPositive mbCnt - | isJust mbCnt && fromJust mbCnt >= 0 = Right mbCnt - | otherwise = Left $ sdocIgnore <+> text "must be >= 0" - mbCnt :: Maybe Int = readMaybe str - sdocIgnore = (text "Ignore count") <+> quotes (text str) - in Right mbCnt >>= checkJust >>= checkPositive + case readMaybe str of + Nothing -> Left $ sdocIgnore <+> "is not numeric" + Just cnt | cnt < 0 -> Left $ sdocIgnore <+> "must be >= 0" + | otherwise -> Right cnt + where + sdocIgnore = text "Ignore count" <+> quotes (text str) setupBreakpoint :: GhciMonad m => GHC.BreakInfo -> Int -> m() setupBreakpoint loc count = do -- cgit v1.2.1