X.C.Desktop: Add type signatures

When we applied hlint hints in bd5b969d9ba24236c0d5ef521c0397390dbc4b37,
the definition of desktopLayoutModifiers got (via the hint to eta
reduce) changed from

    desktopLayoutModifiers layout = avoidStruts layout

to

    desktopLayoutModifiers = avoidStruts

While the former is general enough to infer the type signature

    LayoutClass l a => l a -> ModifiedLayout AvoidStruts l a

the latter just sees the usage site of

    , layoutHook = desktopLayoutModifiers $ layoutHook def

in the desktopConfig function and thus—through the magic of
MonomorphismRestriction—infers the specialized type

    Choose Tall (Choose (Mirror Tall) Full) Window
      -> ModifiedLayout AvoidStruts
           (Choose Tall (Choose (Mirror Tall) Full)) Window

This obviously completely falls apart once someone wants to change the
layout and still uses desktopLayoutModifiers (unaware that it is just
avoidStruts at the moment).  The easy fix is to give things type
signatures, so nothing needs to be inferred.

The _actual_ solution would be, in my opinion, to completely deprecate
X.C.Desktop and remove it in a future release, as well as to completely
rewrite the provided Example.hs.  This needs more deliberation though.

Fixes: https://github.com/xmonad/xmonad-contrib/issues/560
Related: bd5b969d9ba24236c0d5ef521c0397390dbc4b37
This commit is contained in:
slotThe 2021-06-14 18:36:04 +02:00
parent 5067164d19
commit 5995d6c117

View File

@ -57,6 +57,7 @@ module XMonad.Config.Desktop (
import XMonad
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.EwmhDesktops
import XMonad.Layout.LayoutModifier (ModifiedLayout)
import XMonad.Util.Cursor
import qualified XMonad.StackSet as W
@ -165,19 +166,22 @@ import qualified Data.Map as M
-- > adjustEventInput
--
desktopConfig :: XConfig (ModifiedLayout AvoidStruts
(Choose Tall (Choose (Mirror Tall) Full)))
desktopConfig = docks $ ewmh def
{ startupHook = setDefaultCursor xC_left_ptr <+> startupHook def
, layoutHook = desktopLayoutModifiers $ layoutHook def
, logHook = desktopLogHook <+> logHook def
, keys = desktopKeys <+> keys def }
desktopKeys :: XConfig l -> M.Map (KeyMask, KeySym) (X ())
desktopKeys XConfig{modMask = modm} = M.fromList
[ ((modm, xK_b), sendMessage ToggleStruts) ]
desktopLayoutModifiers :: LayoutClass l a => l a -> ModifiedLayout AvoidStruts l a
desktopLayoutModifiers = avoidStruts
-- | 'logHook' preserving old 'ewmh' behavior to switch workspace and focus to
-- activated window.
desktopLogHook :: X ()
desktopLogHook = activateLogHook (reader W.focusWindow >>= doF)