IO behaves oddly if used nested

Lennart Augustsson lennart at
Thu Oct 2 13:47:15 EDT 2003

Alastair Reid wrote:

>>Another question with a trivial answer, what is the result of:
>>  main :: IO (IO ())
>>  main = return (putStr "Hello World!")
> It is a computation which, if executed, will print "Hello World"
>>Clearly it also shows the relation between IO and chosen evaluation
> This isn't clear to me at all - can you explain further?
Is it even type correct with
   main :: IO (IO ())
If it is, it shouldn't be.  It makes no sense.
The value computed by the top level IO action should
have some consumer.  Sensible types for the consumer
(which in some sense is the OS) are () or some exit code.

	-- Lennart

More information about the Haskell mailing list