[Haskell-beginners] Sequential IO processing
Sergey V. Mikhanov
sergey at mikhanov.com
Thu Feb 19 10:27:02 EST 2009
I tried this earlier as well:
sequenceIO [] = return []
sequenceIO (x : xs) = do result <- x
resultTail <- sequenceIO xs
return result : resultTail
This results in:
Couldn't match expected type `IO [a]' against inferred type `[m a]'
In the expression: return result : resultTail
In the expression:
do result <- x
resultTail <- sequenceIO xs
return result : resultTail
In the definition of `sequenceIO':
sequenceIO (x : xs)
= do result <- x
resultTail <- sequenceIO xs
return result : resultTail
>> sequenceIO [] = return []
>> sequenceIO (x : xs) = do result <- x
>> return result : sequenceIO xs
>
> The problem is indeed here. The type of 'sequenceIO xs' is IO [a], but the
> type of result is 'a'. You can't cons an 'a' onto an 'IO [a]'. Thus, what
> you need is something like this:
> sequenceIO [] = return []
> sequenceIO (x : xs) = do result <- x
> xs' <- sequenceIO xs -- to take the
> list out of the IO Monad
> return result : xs'
More information about the Beginners
mailing list