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
There is no way to get the "Int" out of an "IO Int", except to do something else in the IO Monad. The first argument is your initial "IO Int" value that "comboBoxGetActive" is returning. The second is a function that takes the Int value and turns it into some other IO value.
Haskell separates pure functions from computations where side effects must be considered by encoding those side effects as values of a particular type. Specifically, a value of type (IO a) is an action, which if executed would produce a value of type a .
The IO type serves as a tag for operations (actions) that interact with the outside world. The IO type is abstract: no constructors are visible to the user.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With