xmonad / xmonad-contrib

Contributed modules for xmonad
https://xmonad.org
BSD 3-Clause "New" or "Revised" License
579 stars 272 forks source link

Address some `-Wx-Partial` warnings #836

Closed slotThe closed 9 months ago

slotThe commented 9 months ago

Related: https://github.com/xmonad/xmonad-contrib/issues/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 5fc6777b could perhaps use a second pair of eyes, to see whether I've made any illegal transformations.

Commit summary

5fc6777b Reduce head usage

8f735acd Import X.Prelude unqualified if necessary

This gets rid of, for example,

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

-type warnings.

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

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

3a3544b5 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.

fab8ad5b X.U.Stack: Add differentiateTwo

cbb85248 Replace tail with drop 1

Where appropriate.

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

Reexport them instead.

Checklist

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) | ^^^^