以下代码有什么问题:
nextMatch :: (a -> Bool) -> [IO a] -> (IO a, [IO a])
nextMatch f (x:xs) = do
s <- x
if f s then (return x, xs)
else nextMatch f xs
编译错误说:
src\Main.hs:364:10:
Couldn't match expected type `(IO a, t0)' with actual type `IO a'
In a stmt of a 'do' block: s <- x
In the expression:
do { s <- x;
if f s then (return x, xs) else nextMatch f xs }
In an equation for `nextMatch':
nextMatch f (x : xs)
= do { s <- x;
if f s then (return x, xs) else nextMatch f xs }
我想要一个函数,它在列表中搜索匹配项并将匹配的元素加上剩余的列表作为元组返回。
我对haskell还是很陌生,所以这个问题可能很简单......
谢谢!克里斯