Convert [IO Int] to IO [Int] in Haskell?

I have this code that suits me:

f :: [IO Int] -> IO [Int] f [] = return [] f (x:xs) = do a <- x as <- f xs return (a:as) 

But I have a predefined way (msum?)

But I do not see how.

Any help would be appreciated. thanks

+6
source share
1 answer

Yes, it is available in the standard library under the name sequence . It has a more general type than your f : Monad m => [ma] -> m [a] , since it works for any Monad , not just IO .

You can find it yourself by looking for the type [IO a] -> IO [a] in Hoogle .

+22
source

All Articles