这可能是 SO 之间的边界,因为很多问题都是关于 haskell 编程的。但归根结底,这是一个配置问题。
背景和研究
从 0.12 开始,Xmonad 在 xmonad.errors 中抛出此警告(多次):
xmonad.hs:15:14: warning: [-Wdeprecations]
In the use of ‘defaultConfig’
(imported from XMonad, but defined in XMonad.Config):
Deprecated: "Use def (from Data.Default, and re-exported by XMonad and XMonad.Config) instead."
它有效,这只是一个警告。然而,我想了解导致警告的原因(我试图理解它,但已经失败了几个小时)。根据弃用描述,您可能会猜测没有使用fromXMonad.Config
的定义,但事实并非如此。查看代码Default
Data.Default
XMonad.Config
你在开头看到导入:
import XMonad.Core as XMonad hiding
(workspaces,manageHook,keys,logHook,startupHook,borderWidth,mouseBindings
,layoutHook,modMask,terminal,normalBorderColor,focusedBorderColor,focusFollowsMouse
,handleEventHook,clickJustFocuses,rootMask,clientMask)
import qualified XMonad.Core as XMonad
(workspaces,manageHook,keys,logHook,startupHook,borderWidth,mouseBindings
,layoutHook,modMask,terminal,normalBorderColor,focusedBorderColor,focusFollowsMouse
,handleEventHook,clickJustFocuses,rootMask,clientMask)
import XMonad.Layout
import XMonad.Operations
import XMonad.ManageHook
import qualified XMonad.StackSet as W
import Data.Bits ((.|.))
import Data.Default
import Data.Monoid
import qualified Data.Map as M
import System.Exit
import Graphics.X11.Xlib
import Graphics.X11.Xlib.Extras
并且Data.Default
肯定是存在的。然后defaultConfig
(仍在 内Xmonad.Config
) 定义为:
instance (a ~ Choose Tall (Choose (Mirror Tall) Full)) => Default (XConfig a) where
def = XConfig
{ XMonad.borderWidth = borderWidth
... ... ... ... ... ...
, XMonad.rootMask = rootMask
, XMonad.handleExtraArgs = \ xs theConf -> case xs of
[] -> return theConf
_ -> fail ("unrecognized flags:" ++ show xs)
}
-- | The default set of configuration values itself
{-# DEPRECATED defaultConfig "Use def (from Data.Default, and re-exported by XMonad and XMonad.Config) instead." #-}
defaultConfig :: XConfig (Choose Tall (Choose (Mirror Tall) Full))
defaultConfig = def
所以defaultConfig
应该使用Data.Default
,而我可能是做错事的人。
解决方案尝试
xmonad.hs
我发出警告的最小配置 ( ) 是:
import XMonad
main = xmonad defaultConfig { terminal = "urxvt" }
(我的完整 xmonad 配置很大,上面只是复制警告的最小配置。)
我试过:
import Data.Default
import XMonad
main = xmonad defaultConfig { terminal = "urxvt" }
但警告仍然存在。我可以使用main = xmonad XConfig {}
然后枚举每个配置选项,但这会将 90% 复制XMonad.Config
到我自己的xmonad.hs
.
问题
我究竟做错了什么?如何强制使用Data.Default
?我一开始就正确理解了弃用警告吗?
答案1
你不需要导入import Data.Default
这是在 XMonad 本身中导入的
只需要进行一处更改:
import XMonad
main = xmonad defaultConfig { terminal = "urxvt" }
到
import XMonad
main = xmonad def { terminal = "urxvt" }