【发布时间】:2017-07-03 03:37:14
【问题描述】:
所以我在 haskell 中尝试了以下代码,我尝试检测用户是否在字符串中输入了“否”或“否”。我也尝试用字符串替换 [[Char]] ,但它给出了编译错误。
wantGifts :: [[Char]] -> [[Char]]
wantGifts st = [if (x == "No" || x== "no") then "No gifts given" else "But why" | x <- st, x == head st]
上面的代码可以编译,但是当我向它传递一个字符串时,它返回一个错误消息:
*Main> wantGifts "no I dont"
<interactive>:8:11:
Couldn't match type ‘Char’ with ‘[Char]’
Expected type: [[Char]]
Actual type: [Char]
In the first argument of ‘wantGifts’, namely ‘"no I dont"’
In the expression: wantGifts "no I dont"
In an equation for ‘it’: it = wantGifts "no I dont"
【问题讨论】:
-
错误表示该函数需要一个字符串列表(list-of-lists-of-chars),但您没有传递一个。
标签: list function haskell char