[Haskell] IO question

b.i.mills at massey.ac.nz b.i.mills at massey.ac.nz
Fri Jun 11 21:35:25 EDT 2004

While what I want to say has implicitly been said I'd just
like to suggest that there is a simple way to put the whole
matter less cryptically.

The "obvious" question that just about anyone starting with
the IO monad asks is how can I write (IO a -> a)? The "simple"
answer is, you don't have to because you can use (>>=) with
something (a -> b) to write (IO a -> IO b). That is, if you
are dealing with an IO operation, you must always think in
terms of the complete read-modify-write sequence.

This requires you to think explicitly about the temporal
nature of your code, but I see the strength of the IO monad
as being exactly that, it forces you to be explicit. For me 
writing (IO a -> a) is logically non-sensical, you have just 
broken the semantics of IO, that's all. I know what (IO a -> a)
is, because I know that the Haskell language is not the whole
universe. But, it is like *(int *)(&x) in C, the meaning
depends on the implimentation of the language, outside the
semantics of the language per se.



More information about the Haskell mailing list