什麼是用下面的代碼的問題:我想要的搜索列表的匹配,並返回一個函數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