[Haskell-beginners] Why can't I print an IO Integer?
marcin.jan.mrotek at gmail.com
Tue Oct 20 19:36:30 UTC 2015
> An IO Integer is not an integer, it's a promise to read an Integer later. The "sequence" function tells the runtime it's time to make good on that promise.
Not exactly. You don't need "sequence" for a plain (IO Int), only for
a list of IO actions. "sequence" just changes a "list of promises"
into a "promise of a list":
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
When specialized to IO and a list, the function becomes:
sequence :: [IO a] -> IO [a]
Also, for any f: sequence . map f === mapM f
It is when you bind its result to your "main" (with "do" notation or
(>>) and (>>=) operators) when it can interact with the rest of your
program. You can bind it more than once, and it will be executed more
than one time, like any other "IO something".
More information about the Beginners