我正在配置 xmonad,因为我必须启动几个 dzen 实例,所以我决定最好使用一个函数来获取 x 和 y 位置、宽度、高度和文本对齐的参数:
-- mydzen.hs
import Data.List
-- | Return a string that launches dzen with the given configuration.
myDzen :: Num a => a -> a -> a -> Char -> String -> String
myDzen y x w ta e =
intercalate " "
[ "dzen2"
, "-x" , show x
, "-w" , show w
, "-y" , show y
, "-h" , myHeight
, "-fn" , quote myFont
, "-bg" , quote myDBGColor
, "-fg" , quote myFFGColor
, "-ta" , [ta]
, "-e" , quote e
]
quote :: String -> String
quote x = "'" x "'"
-- dummy values
myHeigth = "20"
myFont = "bitstream"
myDBGColor = "#ffffff"
myFFGColor = "#000000"
Could not deduce (Show a) arising from a use of `show'
from the context (Num a)
bound by the type signature for
myDzen :: Num a => a -> a -> a -> Char -> String -> String
at mydzen.hs:(5,1)-(17,13)
Possible fix:
add (Show a) to the context of
the type signature for
myDzen :: Num a => a -> a -> a -> Char -> String -> String
In the expression: show x
In the second argument of `intercalate', namely
`["dzen2", "-x", show x, "-w", ....]'
In the expression:
intercalate " " ["dzen2", "-x", show x, "-w", ....]
显然,删除签名或更改Num a
forShow a
可以解决问题,但我不明白为什么。'arguments' x
,w
并且应该y
是几乎任何类型的数字(, , ecc )。100
550.2
1366 * 0.7
我是 haskell 的新手,直到现在我还无法(清楚地)理解错误或找出问题所在。