什么是用下面的代码的问题:我想要的搜索列表的匹配,并返回一个函数Haskell的IO功能类型不匹配
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 }
:
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
编译错误说匹配元素加上剩下的列表,作为元组。
我还是很新的哈斯克尔,所以这个问题可能是一个很简单的......
谢谢! Chris
一般性评论 - 一元参数(例如'IO [a]'或您的[IO a]')几乎总是一个坏主意。不纯代码通常需要纯粹的参数,使用do-notation或'>> ='将它们应用于monadic值。 – isturdy 2013-05-09 19:34:56