我開始學習Haskell與「學習你一個好主意的Haskell!」我犯了一個奇怪的錯誤,我找不到原因。函數定義在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]
這是這本書的例子,我沒有任何問題。
有人能解釋我的錯誤嗎?
感謝你們的答案;它們相輔相成。 – guillaume8375 2013-04-07 20:46:26