【发布时间】:2015-11-15 14:33:32
【问题描述】:
该函数应该给我搜索元素的位置。
e。 : 索引 'b' "dfbhjbd" -> [3,6]
到目前为止:
索引 b (x:xs) = 长度 ( takeWhile ( /= b) xs )
但是 takeWhile 会在找到匹配的元素后立即停止。所以以下元素将被忽略。
我试过这样的:
index b (x:xs) = length ( tak b xs )
where
tak b [] = []
tak b xs
| b /= x == x:tak b xs
| otherwise = [], tak b xs
除了由于解析错误而无法运行代码之外,它不会显示正确的结果。 有什么建议吗?
【问题讨论】:
标签: haskell