我开始通过“Learn You a Haskell for Great Good!”来学习 Haskell。我犯了一个奇怪的错误,我找不到原因。
这是我输入的代码:
let xs = [if x < 3 then "bang" else "boom" | x <- xs]
以及 GHCi 中的错误文本:
No instance for (Num [Char])
arising from the literal `3'
Possible fix: add an instance declaration for (Num [Char])
In the second argument of `(<)', namely `(3)'
In the expression: x < (3)
In the expression: if x < (3) then "bang" else "boom"
但是当我输入:
let boom xs = [if x < 3 then "bang" else "boom" | x <- xs]
这是书中的例子,我没有任何问题。
有人可以解释我的错误吗?