【发布时间】:2013-05-02 02:35:56
【问题描述】:
我想删除列表中以“h”开头的每个字符串。
["hawrw", "basw", "HasD" , "hgkas"] => ["basw", "HasD"]
我的代码是:
kat (x:xs) = if head x == "h" then kat(xs) else x ++ kat(xs)
为什么它不起作用?以及如何修复我的代码?
【问题讨论】:
-
定义“不起作用”
-
:1:4: 无法匹配预期类型 [[[Char]]]' with actual type(t0, t1)' 在kat', namely("abc", "hef")' 的第一个参数中表达式: kat ("abc", "hef") 在 'it' 的等式中:it = kat ("abc", "hef") 这就是我得到的错误。我只想检查每个字符串的第一个元素是否为 == "h"。如果它是 == "h" 那么我只需将列表的其余部分放入我的函数中如果它不是 == "h" 那么我想保留第一个字符串并将我的函数应用于列表的其余部分.
标签: list haskell recursion multidimensional-array