[Haskell-cafe] IO () and IO [()]
Paulo J. Matos
pocm at soton.ac.uk
Mon Mar 10 18:11:33 EDT 2008
I find it funny that IO () is different from IO [()].
For example, if I define a function to output some lines with mapT, I would do:
outputLines :: Int -> IO ()
outputLines i = mapM (putStrLn . show) (take i $ iterate ((+) 1) 1)
However, this is in fact
outputLines :: Int -> IO [()]
I would like to know if in fact there's any difference in practice
between (), [()], i.e. if in practice the difference matters.
My first guess is that this is just a consequence of the Haskell type
system and so that everything fits this really needs to be like this.
mapM :: (Monad m) => (a -> m b) -> [a] -> m [b]
So I guess that it makes sense that you get IO [()] instead of IO (),
and adding an exception just to say that [()] == () isn't good.
By the way, as a consequence can you possibly get IO (()) or IO ([()])
and are these all different from each other?
Paulo Jorge Matos - pocm at soton.ac.uk
PhD Student @ ECS
University of Southampton, UK
Sponsor ECS runners - Action against Hunger:
More information about the Haskell-Cafe