Reputation: 123
I have this code that fits my need:
f :: [IO Int] -> IO [Int]
f [] = return []
f (x:xs) = do
a <- x
as <- f xs
return (a:as)
But I thougth there would be a predefined way (msum ?)
But I can't see how.
Any help would be welcome. Thx
Upvotes: 5
Views: 583
Reputation: 15078
Yes, it's available in the standard library under the name sequence
. It has a more general type than your f
: Monad m => [m a] -> m [a]
, since it works for any Monad
, not just IO
.
You could find it yourself by searching for type [IO a] -> IO [a]
on Hoogle.
Upvotes: 21