【发布时间】:2015-11-25 13:34:17
【问题描述】:
我有一个函数:
setDisplays :: Char -> [String] -> IO()
setDisplays mode dIds
| mode == 'l' = chngDispl (head dIds)
| mode == 'e' = chngDispl (tail dIds)
where
chngDispl on = mapM_ (\id -> callProcess "xrandr" ["--output", id, "--auto"]) on
获取带有 xrandr 提供的 Displays id 的字符串列表,看起来像 ["eDP1", "HDMI1"]。该列表通过绑定IO () 传递给setDisplays:
getDisplays >>= setDisplays 'e'
现在,我收到以下错误消息: parser.hs:50:37:
Couldn't match type ‘Char’ with ‘[Char]’
Expected type: [[String]]
Actual type: [String]
In the first argument of ‘head’, namely ‘dIds’
In the first argument of ‘chngDispl’, namely ‘(head dIds)’
Failed, modules loaded: none.
我不明白。甚至 ghc-mod 都告诉我,第一次提到的名称 dIds 标识 [String],当我在函数调用中使用 ghc-mod 进行类型检查时,它标识 [[[Char]]]。这里发生了什么?
【问题讨论】:
-
type String = [Char]