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

Address some -Wx-Partial warnings #836

Merged
merged 7 commits into from
Oct 20, 2023
Merged

Conversation

slotThe
Copy link
Member

@slotThe slotThe commented Oct 15, 2023

Related: #830

I sort of ran out of steam at some point, but this is a good chunk of them. Most of these are relatively automatic replacements, only 5fc6777 could perhaps use a second pair of eyes, to see whether I've made any illegal transformations.

Commit summary

5fc6777 Reduce head usage

8f735ac Import X.Prelude unqualified if necessary

This gets rid of, for example,

The import of ‘liftA2’ from module ‘XMonad.Prelude’ is redundant

-type warnings.

9399a1e X.{U,H}.Debug{Window,Events}: Replace tail with non-empty lists

ec3a9ee X.L.Groups: Rewrite gen using infinite streams

3a3544b X.Prelude: Add infinite stream type

Stolen from X.A.MostRecentlyUsed. This can be used in favour of lists
when we know the generated lists are definitely infinite.

fab8ad5 X.U.Stack: Add differentiateTwo

cbb8524 Replace tail with drop 1

Where appropriate.

c8c8147 X.A.CycleWindows: Move rot{Up,Down} to X.A.RotSlaves

Reexport them instead.

Checklist

  • I've read CONTRIBUTING.md

  • I've considered how to best test these changes (property, unit,
    manually, ...) and concluded:

    I haven't installed GHC 9.8 (yet), so this is mostly untested. Everything should work, though.

  • I updated the CHANGES.md file

    Where appropriate.

Remaining nits

Remaining nits…
    XMonad/Layout/OneBig.hs:68:22: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
       |
    68 |             master = head ws
       |                      ^^^^

    XMonad/Layout/MultiColumns.hs:100:47: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    100 |                       where newval =  max 0 $ head r + x
        |                                               ^^^^

    XMonad/Util/Image.hs:45:26: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
       |
    45 | imageDims img = (length (head img), length img)
       |                          ^^^^

    XMonad/Actions/Workscreen.hs:112:40: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    112 |                               let ws = head . workspaces $ a !! wscrId
        |                                        ^^^^

    XMonad/Actions/SwapPromote.hs:243:30: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    243 |                 mh = let w = head . W.integrate $ s3
        |                              ^^^^

    XMonad/Hooks/ServerMode.hs:95:35: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
       |
    95 |          let atom = fromIntegral (head dt)
       |                                   ^^^^

    XMonad/Actions/WorkspaceCursors.hs:100:34: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    100 |     where x = end $ map return $ head a
        |                                  ^^^^

    XMonad/Util/Timer.hs:56:43: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
       |
    56 |   if mt == a && dt /= [] && fromIntegral (head dt) == ti
       |                                           ^^^^

    XMonad/Hooks/Place.hs:196:49: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    196 |                       let (workspace, screen) = head infos
        |                                                 ^^^^

    XMonad/Prompt.hs:537:21: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    537 |   let defaultMode = head modes
        |                     ^^^^

    XMonad/Prompt.hs:647:26: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    647 |                 return $ head l
        |                          ^^^^

    XMonad/Prompt.hs:779:76: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    779 |               if command st == hlCompl then put st else replaceCompletion (head cs)
        |                                                                            ^^^^

    XMonad/Prompt.hs:1386:13: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
         |
    1386 |     let c = head s
         |             ^^^^

    XMonad/Prompt.hs:1594:43: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
         |
    1594 |   (asc, desc) <- io $ textExtentsXMF fs $ head compl
         |                                           ^^^^

    XMonad/Prompt.hs:1795:25: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
         |
    1795 | deleteConsecutive = map head . group
         |                         ^^^^

    XMonad/Actions/WindowGo.hs:93:70: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
       |
    93 | ifWindow qry mh = ifWindows qry (windows . appEndo <=< runQuery mh . head)
       |                                                                      ^^^^

    XMonad/Actions/WindowGo.hs:168:30: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    168 |     _ -> windows . focusFn . head $ ws
        |                              ^^^^

    XMonad/Prompt/OrgMode.hs:528:26: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    528 |       str  <- munch  (/= head ptn)
        |                          ^^^^

    XMonad/Hooks/StatusBar/PP.hs:467:14: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    467 |     in fst $ head $ dropWhile (uncurry (/=)) $ zip xs $ tail xs
        |              ^^^^

    XMonad/Hooks/Minimize.hs:47:36: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
       |
    47 |       let message = fromIntegral . head $ dt
       |                                    ^^^^

    XMonad/Util/ExclusiveScratchpads.hs:177:11: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    177 |     mh <- head . map hook <$> ys  -- ys /= [], so `head` is fine
        |           ^^^^

    XMonad/Util/ExclusiveScratchpads.hs:178:11: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    178 |     n  <- head . map name <$> ys  -- same
        |           ^^^^

    XMonad/Layout/Combo.hs:124:63: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    124 |                                                  (maybe super head msuper')
        |                                                               ^^^^

    XMonad/Layout/Combo.hs:125:60: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    125 |                                                  (maybe l1 head ml1')
        |                                                            ^^^^

    XMonad/Layout/Combo.hs:126:60: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    126 |                                                  (maybe l2 head ml2')
        |                                                            ^^^^

    XMonad/Layout/TallMastersCombo.hs:247:61: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    247 |         let subMaster = if null w2 then Nothing else Just $ head w2
        |                                                             ^^^^

    XMonad/Layout/TallMastersCombo.hs:254:61: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    254 |         let subMaster = if null w2 then Nothing else Just $ head w2
        |                                                             ^^^^

    XMonad/Actions/GridSelect.hs:661:61: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    661 |                                 s = TwoDState { td_curpos = head coords,
        |                                                             ^^^^

    XMonad/Util/EZConfig.hs:441:23: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    441 |         combine ks = (head . fst . head $ ks,
        |                       ^^^^

    XMonad/Util/EZConfig.hs:441:36: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    441 |         combine ks = (head . fst . head $ ks,
        |                                    ^^^^

    XMonad/Util/EZConfig.hs:443:29: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    443 |         fstKey = (==) `on` (head . fst)
        |                             ^^^^

    XMonad/Util/EZConfig.hs:547:27: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    547 |         dups = map (snd . head)
        |                           ^^^^

    XMonad/Actions/Navigation2D.hs:887:38: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    887 |     newwinset = winset { W.current = head newscrs
        |                                      ^^^^

    XMonad/Actions/Prefix.hs:169:37: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from XMonad.Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
        |
    169 |               Raw a -> replicate a (head events) ++ [key]
        |                                     ^^^^

    XMonad/Actions/ShowText.hs:91:44: warning: [GHC-63394] [-Wx-partial]
        In the use of ‘head’
        (imported from Prelude, but defined in GHC.List):
        "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
       |
    91 |          (whenJust (lookup (fromIntegral $ head d) m) deleteWindow)
       |                                            ^^^^

XMonad/Hooks/DebugEvents.hs Outdated Show resolved Hide resolved
XMonad/Util/DebugWindow.hs Outdated Show resolved Hide resolved
Where appropriate.
XMonad/Util/Stack.hs Outdated Show resolved Hide resolved
XMonad/Prelude.hs Outdated Show resolved Hide resolved
Stolen from X.A.MostRecentlyUsed. This can be used in favour of lists
when we know the generated lists are definitely infinite.
This gets rid of, for example,

    The import of ‘liftA2’ from module ‘XMonad.Prelude’ is redundant

-type warnings.
@slotThe slotThe merged commit 9c4325f into xmonad:master Oct 20, 2023
17 checks passed
@slotThe slotThe deleted the wx-partial branch October 20, 2023 06:22
slotThe added a commit to slotThe/xmonad-contrib that referenced this pull request Oct 27, 2023
slotThe added a commit to slotThe/xmonad-contrib that referenced this pull request Oct 27, 2023
slotThe added a commit that referenced this pull request Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants